powershell - Can I send some text to the STDIN of an active process under Windows? -
i searched web question , landed on server fault:
can send text stdin of active process running in screen session?
seems ridiculously easy achieve under linux. need win32 command prompt.
background: have application polls stdin , if press x key, application terminates. now, want automated testing, test application , shut down.
note: killing process not option since i'm investigating problems arise during shutdown of application.
.net framework's process , processstartinfo classes can used create , control process. since windows powershell can used instantiate .net objects, ability control every aspect of process available within powershell.
here's how can send dir command cmd.exe process (make sure wrap in .ps1 file , execute script):
$psi = new-object system.diagnostics.processstartinfo; $psi.filename = "cmd.exe"; #process file $psi.useshellexecute = $false; #start process it's own executable file $psi.redirectstandardinput = $true; #enable process read standard input $p = [system.diagnostics.process]::start($psi); start-sleep -s 2 #wait 2 seconds process can , running $p.standardinput.writeline("dir"); #standardinput property of process .net streamwriter object
Comments
Post a Comment