You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was recently trying to write a GUI wrapper around commands like netstat -r (on macOS). Due to hostname lookup, that command can take a while to run, but in a typical Terminal, incomplete results will show up while it is running. However, I wasn't able to recreate that behavior — portions of the standard output showing up before the command has finished running — with System.Console, with code like this:
usingvarprocess=newProcess{StartInfo=newProcessStartInfo("netstat"){RedirectStandardOutput=true}};// `Output` here is a data-bound to a Xamarin Forms text fieldprocess.OutputDataReceived+=async(_,args)=>Device.InvokeOnMainThreadAsync(()=>Output+=s+Environment.NewLine);process.EnableRaisingEvents=true;process.Start();process.BeginOutputReadLine();process.WaitForExit();
Instead, all text appears at once once the process has exited.
Digging led me to various OS-specific workarounds to disable buffering. For my case, I could wrap the command in script -q /dev/null, and get a behavior just like in Terminal: results appear immediately, line by line.
What I'm hoping for is some kind of DisableBuffering or RunAsPseudoTerminal property on ProcessStartInfo.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I was recently trying to write a GUI wrapper around commands like
netstat -r
(on macOS). Due to hostname lookup, that command can take a while to run, but in a typical Terminal, incomplete results will show up while it is running. However, I wasn't able to recreate that behavior — portions of the standard output showing up before the command has finished running — withSystem.Console
, with code like this:Instead, all text appears at once once the process has exited.
Digging led me to various OS-specific workarounds to disable buffering. For my case, I could wrap the command in
script -q /dev/null
, and get a behavior just like in Terminal: results appear immediately, line by line.What I'm hoping for is some kind of
DisableBuffering
orRunAsPseudoTerminal
property onProcessStartInfo
.This also plays into the System.Console re-design, maybe.
Beta Was this translation helpful? Give feedback.
All reactions