Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C# GET RESULT OUTPUT AND ERROR OUTPUT FROM COMMAND LINES
- // From: https://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output/29753402#29753402
- static void runCommand()
- {
- Process process = new Process();
- process.StartInfo.FileName = "cmd.exe";
- process.StartInfo.Arguments = "/c DIR"; // Note the /c command (*)
- process.StartInfo.UseShellExecute = false;
- process.StartInfo.RedirectStandardOutput = true;
- process.StartInfo.RedirectStandardError = true;
- process.Start();
- //* Read the output (or the error)
- string output = process.StandardOutput.ReadToEnd();
- Console.WriteLine(output);
- string err = process.StandardError.ReadToEnd();
- Console.WriteLine(err);
- process.WaitForExit();
- }
Advertisement
Add Comment
Please, Sign In to add comment