I'm at the end of my rope here. I've googled for weeks and looked at samples on places like this, and I'm doing everything those examples are, so why isn't it working? (I searched these forums and found nothing helpful on this subject.)
I'm using:
Visual Studio 2005 (8.0)
.NET 2.0
C#
The sample program I'm trying to run as a process is written in C:
When I run test2.exe on the command line, it outputs those two messages to the console.Code:#include <stdio.h> main() { printf ("This message was sent to stdout.\n"); fprintf (stderr, "This message was sent to stderr.\n"); }
I've tried the different methods (async and sync), but this is what I'm trying (and most sources say to do):
Like I've said, I've tried many different configurations, waiting before reading, using a while to read the output line by line, the event throwing BeginOutputRead things... Nothing's worked. Output is always empty. Can anyone help me?Code:private string RunTest() { string output = string.Empty; Process test= new Process(); test.StartInfo.UseShellExecute = false; test.StartInfo.RedirectStandardOutput = true; test.StartInfo.CreateNoWindow = true; test.StartInfo.FileName = @"C:\temp\djgpp\test2.exe"; test.Start(); StreamReader srOutput = test.StandardOutput; output = srOutput.ReadToEnd(); test.WaitForExit(); test.Close(); return output; }




Reply With Quote