powershell - Is Out-Host buffering? -
i ha function, call application &
operator. application produces several line command line output, downloads files, , returns string:
& "app.exe" | out-host $var = ... return $var
it seems, on console appears output produced app.exe
after app.exe
terminates. user not have real time information file downloading. there way continuously update console when app.exe
running?
many console applications buffer theirs output stream, if known redirected. actually, it standard behavior of c library. so, buffering done app.exe
, because of redirection, not out-host
.
solution not redirect output of app.exe
, when outer command redirected. should know exact condition, when powershell not redirect output stream of console application , link directly own output stream, console interactive powershell.exe
session. conditions is:
- command last item in pipeline.
- command piped
out-default
.
solution wrap command script block, , pipe script block out-default
:
& { & "app.exe" } | out-default
the other solution use start-process
cmdlet -nonewwindow
, -wait
parameters:
start-process "app.exe" -nonewwindow -wait
Comments
Post a Comment