c# - I need cmd output and errors to be posted on a textblock at run time -
currently have command this. first, upon button click event execute batch file , create new text file saving log, results , erros text file. create textblock textblock shows these results , errors @ during process of running batch file. possible?
my current code writing text file:
system.diagnostics.process runantc = new system.diagnostics.process(); runantc.startinfo.filename = "c:\\gui\\batch.bat"; runantc.startinfo.useshellexecute = false; runantc.startinfo.redirectstandardoutput = true; runantc.startinfo.redirectstandarderror = true; runantc.start(); string procoutput = runantc.standardoutput.readtoend(); string procerror = runantc.standarderror.readtoend(); // create writer , open file textwriter outputlog = new streamwriter("c:\\gui\\processoutput.txt"); outputlog.write(procoutput); outputlog.close(); // create writer , open file textwriter outputerror = new streamwriter("c:\\gui\\error.txt"); outputerror.write(procerror); outputerror.close();
edit 1: understand code:
string procoutput = runantc.standardoutput.readtoend();
reads out output start end, not during run process think question ask whether if can replace can see @ runtime
if understand want do, in addition writing output log file, while process running, you'd display output/errors textblock, allowing watch process's output it's executing. right? have not done this, if it's want do, should @ listening output/error asynchronously, , setting event handler proc call when writes output or errors. see documentation on beginerrorreadline @ msdn , documentation on errordatareceived similar event handler exists output.
Comments
Post a Comment