c# - Custom Powershell Host Invoke external program without console window -
i'm writing embedded powershell host in c# (windows application), , if there external program called in pipeline console window flashes it's executed. ping , netstat examples of shown in following code snippet
using (powershell powershellinstance = powershell.create()) { powershellinstance.addscript("get-content test.txt; ls; ping www.google.com"); powershellinstance.invoke(); # ...more code here print output etc }
once ping command reached in pipeline console window popup execute command , return results. without console window showing. i've searched , found examples of how deal starting process external commands , redirecting output.
i can of course, how test if command in pipeline call external program?
i able handle generically if possible; meaning don't want test specific programs (e.g. ping, netstat, net) if don't have to. native powershell.exe it's somehow possible.
it turns out expected behavior of invoking console commands. in windows 7 , above conhost.exe responsible handling calls console programs. in case, ping , netstat trigger instance of conhost created, handles request, returns results, , remains open. conhost.exe starting causing console flash i'm seeing. fact remains open why seeing console window flash once. once conhost connected calling process subsequent console commands handled same instance.
i'm marking answer because new question should created address conhost specifically.
source. windows internals part 1
Comments
Post a Comment