Tuesday 15 January 2013

Save The Cmd output into txt file in C# -



Save The Cmd output into txt file in C# -

how can save cmd commands txt file in c#

or how can display command prompt in c#

here code

private void button1_click(object sender, eventargs e) { var p = new process(); string path = @"c:\users\microsoft"; string argu = "-na>somefile.bat"; processstartinfo process = new processstartinfo("netstat", argu); process.redirectstandardoutput = false; process.useshellexecute = false; process.createnowindow = false; process.start(process); p.startinfo.workingdirectory = path; p.startinfo.filename = "sr.txt"; p.start(); p.waitforexit(); }

you can redirect standard output:

using system; using system.diagnostics; using system.io; class programme { static void main() { // // setup process processstartinfo class. // processstartinfo start = new processstartinfo(); start.filename = @"c:\7za.exe"; // specify exe name. start.useshellexecute = false; start.redirectstandardoutput = true; // // start process. // using (process process = process.start(start)) { // // read in text process streamreader. // using (streamreader reader = process.standardoutput) { string result = reader.readtoend(); console.write(result); } } } }

code here

also answer: redirecting output text file c#

c# cmd

No comments:

Post a Comment