capture cmd output and display in textbox

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 2 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jack_jones
Posts: 1
Last visit: Sun Jun 20, 2021 10:38 am

capture cmd output and display in textbox

Post by jack_jones »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: powershell studio 2021
Operating system: windows 10
PowerShell version(s): 5.1
32-bit version of software? no

I'm trying to convert existing working code into powershell studio.
$ComputerName = $InputBox2.text;
$psx =Join-Path $PSToolsPath Psexec64.exe
$results = & $psx -accepteula -nobanner \\$ComputerName netstat -an
foreach($r in $results)
{

$outputBox.Appendtext(("$r") + ("`r`n"))
}

problem is that when i run this in powershell studio the command opens a cmd window runs the netsta -an but the output is not in the $results variable so i cannot send it to the $outputBox. This works in my original script. I suspect its because a cmd window is opening and the output is lost somewhere. Any Ideas how i can capture the result ?

DO NOT POST LICENSES, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 9:46 am
Answers: 39
Been upvoted: 30 times

Re: capture cmd output and display in textbox

Post by brittneyr »

[Topic moved by moderator to PowerShell GUIs forum]
Brittney
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: capture cmd output and display in textbox

Post by Alexander Riedel »

Looks like you are missing the Out-String
This might help:

https://jackgruber.github.io/2018-05-11 ... ss-output/
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 2 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked