c++ - Program output is different when executed through Powershell remote session -
i'm developing windows console application, using visual studio 2010, prints progress percentage on screen such last number gets overwritten current number. i'm using carriage return achieve so:
std::wcout << "[running: " << std::setw(3) << std::setprecision(3) << percent << "%]" << '\r' ;
when execute program through powershell on remote host using pssesion:
enter-pssession www.xxx.yyy.zzz -credential <username> [www.xxx.yyy.zzz]: ps c:\> .\test.exe
it behaves differently compared when executed locally either in powershell or in cmd.exe. face following 3 problems:
1) console output of program different, in that, instead of overwriting [running xx%]
printing in next line so:
[running 1%] [running 2%] [running 3%] [running 4%] ...
this similar happens when output of program redirected file (lone carriage returns
or newlines
replaced carriage returns
+newlines
combinations).
2) output doesn't shows , when program writes cout. comes @ once @ end of execution. powershell caches output of remote program , sends caller once? if there significant time difference between 2 lines (line meaning output between 2 newline
s) first line gets printed if waits time newline
, if received, again goes waiting state, if not received within time period (~500ms), sends output till last newline
(and not accumulated output) caller. can seen code, there no newline
resulting in [running xx%]
being printed @ once @ end.
3) @ point in program need user's confirmation, cin.fail()
returns true
in remote execution. so, there way take user input in such execution environment? or there way detect program being executed remotely through powershell (eg. env variable)?
any related point appreciated. :)
with respect 1), winrm protocol powershell remoting input/output stream commands , serialized output. has no terminal emulation capabilities, when run things remotely, output fed sequentially 1 line @ time. if used ssh or telnet remote shell of powershell.exe, see expect.
as 2), default output buffermode appears "block" explain behaviour you're seeing. can change new-pssessionoption
cmdlet create configuration session created new-pssession
can passed -session parameter on remoting aware cmdlets. option outputbufferingmode
. if set none
, should desired behaviour.
# default output buffering mode "none" default options $s = new-pssession localhost -sessionoption (new-pssessionoption) enter-pssession $s
for 3), you should able accept input interactively iirc. looks interactive stuff doesn't work right - may have misremembered this.
Comments
Post a Comment