file - How to use C# Stream Reader to save a completion of a process? -
i have program uses cmd program execute various arguements.
the arguements work in normal cmd c:\temp\bin\fls.exe -m c: -r c:\temp\image.dd > c:\temp\bin\ntfs.bodyfile .
the c# program have written works till c:\temp\bin\fls.exe -m c: -r c:\temp\image.dd not execute > c:\temp\bin\ntfs.bodyfile means save process ntfs.bodyfile.
i have read many other websites , point problem of program missing streamreader save completion of process file. can please advise on program allow process saved file? thanks!
one such similar website has same problem be: streamreader file?
using system; using system.collections.generic; using system.linq; using system.text; using microsoft.win32; using system.diagnostics; namespace consoleapplication1 { class program { static void main(string[] args) { process process = new process(); process.startinfo.filename = "c:\\temp\\bin\\fls.exe"; process.startinfo.arguments = "-m c: -r c:\\temp\\image.dd > c:\\temp\\bin\\ntfs.bodyfile"; process.startinfo.useshellexecute = false; process.startinfo.redirectstandardoutput = true; process.startinfo.redirectstandardinput = true; process.startinfo.redirectstandarderror = true; process.start(); system.io.streamreader reader = process.standardoutput; string sres = reader.readtoend(); console.writeline(sres); reader.close(); } } }
it's shell performs redirection, part of arguments list being handed straight fls. should remove it.
you can read directly standard out , error, , save data way - or call cmd , give arguments make redirect output.
note if do use standard output , standard error, should reading 1 of them different thread - or don't redirect it. if process writes lot of data standard error, you're not reading , run out of buffer space , block.
Comments
Post a Comment