Read Console Context

  • Thread starter Thread starter laszlo.csabi
  • Start date Start date
L

laszlo.csabi

I'm trying to create an application where I can run an certain exe file
which runs inside a console window and print the results in it. I would
like to capture the result displayed on the console, but the actual
stream I got back from the process is empty.
If you guys could point me to the right direction what I'm doing wrong,
would be great.

My code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace Svnhook
{
class Program
{
static void Main(string[] args)
{
Process compiler = new Process();
compiler.StartInfo.FileName = "cmd.exe";
compiler.StartInfo.Arguments = @" /c svnlook changed
c:\InetPub\svn\repos ";
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();
string result = compiler.StandardOutput.ReadToEnd();
compiler.WaitForExit();

}
}
}

If I open a Console window and run this command manually :
"svnlook changed c:\InetPub\svn\repos"

I got the following result in the Console

"svnlook: Transaction '<null/ is not based on a revision"

That would be the result I'd like to capture.

If I run my code in debuging mode the result is empty, however I could
see it in the Console window.

So, If some could tell me where I'm failing I would appreciate it.
 
I'm trying to create an application where I can run an certain exe file
which runs inside a console window and print the results in it. I would
like to capture the result displayed on the console, but the actual
stream I got back from the process is empty.
If you guys could point me to the right direction what I'm doing wrong,
would be great.

My code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace Svnhook
{
class Program
{
static void Main(string[] args)
{
Process compiler = new Process();
compiler.StartInfo.FileName = "cmd.exe";
compiler.StartInfo.Arguments = @" /c svnlook changed
c:\InetPub\svn\repos ";
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();
string result = compiler.StandardOutput.ReadToEnd();
compiler.WaitForExit();

}
}
}

I would try getting rid of the "/c" in your command arguments. The
FileName you want to run should be "svnlook" and the arguments should be
"changed C"\\IntetPub\\svn\\repos".
 
Back
Top