c# - How to capture only one line from a console process? -
i have application starts , reads standard output of console process. in console process call dll files write console..but dont want capture messages, want capture output string send.
i tried doing :
verbosemethod(); //method writting things console output = dllmethod(); //method returning want console.clear(); console.out.write(output)
i doing believe reading before console.clear() executes :
exeprocess.beginoutputreadline(); string errstring = exeprocess.standarderror.readtoend();
can give me alternative this? wait until last output message given or of sort?
edit
i believe (if exists)..can tell console not redirect output or not write @ point , allow write once again somewhere else in code? :
console.closebuffer(); console.openbuffer();
you should try using asychronous redirect of output, , turn on , off 'enableraisingevents' capturing between execution want. use beginoutputreadline() , canceloutputread() start/stop console reading.
var myoutput = new stringbuilder(); var myprocess = new process(); myprocess.startinfo = new processstartinfo(path, command); myprocess.startinfo.useshellexecute = false; myprocess.startinfo.redirectstandardoutput = true; myprocess.startinfo.redirectstandarderror = true; myprocess.enableraisingevents = true; myprocess.outputdatareceived += (object sendingprocess, datareceivedeventargs e) => { if (e.data != null) { myoutput.appendline(e.data); } }; myprocess.errordatareceived += (object sendingprocess, datareceivedeventargs e) => { if (e.data != null) { myoutput.appendline(e.data); } }; myprocess.start(); verbosemethod(); //start capture here! myprocess.beginerrorreadline(); myprocess.beginoutputreadline(); dllmethod();
Comments
Post a Comment