c# - Redirecting StandardOutput when it updates lines instead of making new ones -


i launching rsync inside app. right works fine, opens console window, prompts me password, , shows file progress files copy.

public static int syncfolder(string sourcefolder, string destfolder) {      process rsync = new process();     rsync.startinfo.filename = path.combine(rsyncpath, "rsync.exe");     rsync.startinfo.useshellexecute = true;     rsync.startinfo.arguments = string.join(" ", new[] { "-rltzh --progress --chmod=a=rw,da+x", fileutils.encodeparameterargument(sourcefolder), fileutils.encodeparameterargument(destfolder) });     rsync.start();     rsync.waitforexit();      return rsync.exitcode; } 

the problem don't want separate console window opened. display text progress inside control of type , respond prompts (like entering password) inside program itself.

public int syncfolder(string sourcefolder, string destfolder) {      process rsync = new process();     rsync.startinfo.filename = path.combine(rsyncpath, "rsync.exe");     rsync.startinfo.useshellexecute = false;     rsync.startinfo.redirectstandardinput = true;     rsync.startinfo.redirectstandardoutput = true;     rsync.startinfo.redirectstandarderror = true;     rsync.startinfo.arguments = string.join(" ", new[] { "-rltzh --progress --chmod=a=rw,da+x", fileutils.encodeparameterargument(sourcefolder), fileutils.encodeparameterargument(destfolder) });      rsync.errordatareceived += rsync_errordatareceived;     rsync.outputdatareceived += rsync_outputdatareceived;      rsync.start();     bindtouiconrol(rsync.standardinput);      rsync.waitforexit();      return rsync.exitcode; }  private void rsync_outputdatareceived(object sender, datareceivedeventargs e) {     //magic! }  private void rsync_errordatareceived(object sender, datareceivedeventargs e) {     //even more magic! }  private void bindtouiconrol(streamwriter standardinput) {    if(this.invokerequired)    {        this.begininvoke(new action<streamwriter>(bindtouiconrol), standardinput);        return;    }     //hook events here single line text box dumps it's text in when hit enter. } 

and stuck. if did not have %'s kept updating on same line have keep dumping new lines come in, how handle line being re-used new value put in it?

my dream solution have kind of console window embedded inside form itself, similar hyperterminal did in older versions of windows, have no idea how do in .net.


here example program show issue

public class program {      private static void main(string[] args)     {         console.write("1");         console.writeline();          console.write("2");         console.cursorleft = 0;         console.write("3");         console.writeline();          console.write("4");         console.writeline();     } } 

how write forms application display

 1 3 4 

in control after runs process.

this not trivial problem solve in general. has fact windows/console applications don't write standard out , standard error, write "console". there various hacks , things make standard out , standard error work ok when care of text , of error text @ once, nothing works interactively, because way things buffered.

follow discussion more information:

writing console wrapper in c#?


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -