AndiiX
AndiiX

Reputation: 37

Get CMD output in C#

i'm using a syntax check programm, which is called like this in CMD:

"C:\Program Files (x86)\BoLPad\SyntaxCheck\\luac5.1.exe" C:\Users\Andi-PC\Desktop\test\syntax.lua

-> So i call the program and as parameter the file to be checked. Now i'm trying to get the result of the check (so the output in CMD) to my C# Application.

I'm wondering if it's possible, i tried alot even using >command.txt to get the file out of the CMD, but there's nothing in it. So i either need a working output of the text out of CMD or get the CMD text... Any ideas?

Upvotes: 0

Views: 1027

Answers (1)

Ashigore
Ashigore

Reputation: 4678

You can do it using a process and redirecting the output stream like this:

ProcessStartInfo psi = new ProcessStartInfo(@"C:\Program Files (x86)\BoLPad\SyntaxCheck\luac5.1.exe", @"C:\Users\Andi-PC\Desktop\test\syntax.lua");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
Process process = Process.Start(psi);
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();

Upvotes: 3

Related Questions