0

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?

Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67
AndiiX
  • 37
  • 6
  • 1
    possible duplicate of [Capturing console output from a .NET application (C#)](http://stackoverflow.com/questions/186822/capturing-console-output-from-a-net-application-c) – MichaC Nov 17 '13 at 17:05

1 Answers1

3

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();
Ashigore
  • 4,618
  • 1
  • 19
  • 39
  • Gives me no output at all, had this problem before... In the CMD window it shows the text that i wanted to get. – AndiiX Nov 17 '13 at 17:13
  • @user3002079 Check the code again, I updated it to fix an error. If that still doesnt work try reading from the Error stream instead of the Output stream, I have seen some commandline apps do that for some reason. – Ashigore Nov 17 '13 at 17:14
  • WOW! Thanks, really! Redirecting ErrorOutput was the right thing to do here ;) I tried so much to get the text, still not getting it can be something different than usual output. Thanks ! – AndiiX Nov 17 '13 at 17:18