process - Reading console stream continually in c# -


i want read continues output stream of cmd in c#. know can redirect standard output stream , read it. following code:

        system.diagnostics.processstartinfo pi= new system.diagnostics.processstartinfo(programpath,params);         pi.redirectstandardoutput = true;         pi.useshellexecute = false;         pi.createnowindow = true;          system.diagnostics.process proc= new system.diagnostics.process();         proc.startinfo = pi;         proc.start();          string result = proc.standardoutput.readtoend(); 

but gives whole output @ once. if issue ping command -t argument? how can read stream continually?

you're calling readtoend block until process terminates. can repeatedly call read or readline instead. however, should consider either doing in different thread or using events such outputdatareceived this. (if you're using events, need call beginoutputreadline enable events - see msdn examples details.)

the reason potentially reading on different thread if need read both standard error , standard output, need make sure process doesn't fill buffer - otherwise block when writing, leading deadlock. using asynchronous approach makes simpler handle this.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -