Display output of the CMD in real time inside 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.
User avatar
jvierra
Posts: 12550
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Display output of the CMD in real time inside TextBox

Post by jvierra » Wed Aug 08, 2018 11:03 am

Here is how to make a full async read work in a form.
Attachments
Demo-Capture StandardOutAsync.psf
(17.2 KiB) Downloaded 8 times

User avatar
davidc
Posts: 5339
Joined: Thu Aug 18, 2011 4:56 am

Re: Display output of the CMD in real time inside TextBox

Post by davidc » Wed Aug 08, 2018 11:17 am

If you don't set the $process.SynchronizingObject property, it will crash PowerShell. That was the issue I was having before.
David
SAPIEN Technologies, Inc.

User avatar
jvierra
Posts: 12550
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Display output of the CMD in real time inside TextBox

Post by jvierra » Wed Aug 08, 2018 11:55 am

The exception is being missed by the scriptdriver. PowerShell CLI also misses the exception.
Faulting application name: scriptdriver64.exe, version: 1.4.48.0, time stamp: 0x5ae7594d
Faulting module name: KERNELBASE.dll, version: 10.0.17134.165, time stamp: 0xb0bb231d
Exception code: 0xe0434352
Fault offset: 0x000000000003a388
Faulting process id: 0x4dd0
Faulting application start time: 0x01d42f48f7837a64
Faulting application path: C:\Program Files (x86)\Common Files\SAPIEN Debugger 2018\scriptdriver64.exe
Faulting module path: C:\WINDOWS\System32\KERNELBASE.dll
Report Id: bd3e6bcf-7744-4b97-b1a6-c5b9b50365ce
Faulting package full name:
Faulting package-relative application ID:

User avatar
ALIENQuake
Posts: 15
Joined: Sun Mar 03, 2013 12:45 pm

Re: Display output of the CMD in real time inside TextBox

Post by ALIENQuake » Thu Aug 09, 2018 3:48 pm

Guys that looks amazing, let me digg into it and post back :shock:

User avatar
ALIENQuake
Posts: 15
Joined: Sun Mar 03, 2013 12:45 pm

Re: Display output of the CMD in real time inside TextBox

Post by ALIENQuake » Sat Aug 11, 2018 5:54 am

I did it! Now I con not only display progress in real time but also send input if application suddenly ask for it! I'm using:

Code: Select all

$buttonSendInput_Click={
	$process.StandardInput.WriteLine($textboxInput.Text)
}
and it works. I didn't know much about process.EnableRaisingEvents and $process.SynchronizingObject so thank you for you help.

User avatar
davidc
Posts: 5339
Joined: Thu Aug 18, 2011 4:56 am

Re: Display output of the CMD in real time inside TextBox

Post by davidc » Tue Aug 14, 2018 8:10 am

FYI, I plan to will integrate this into the Process Tracker Control Set in an upcoming service build.
David
SAPIEN Technologies, Inc.

Post Reply