|
-
Aug 14th, 2007, 10:31 AM
#1
Thread Starter
New Member
[2.0] Redirecting Output - What am I doing wrong?
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:
Code:
#include <stdio.h>
main()
{
printf ("This message was sent to stdout.\n");
fprintf (stderr, "This message was sent to stderr.\n");
}
When I run test2.exe on the command line, it outputs those two messages to the console.
I've tried the different methods (async and sync), but this is what I'm trying (and most sources say to do):
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;
}
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?
-
Aug 21st, 2007, 01:08 AM
#2
Re: [2.0] Redirecting Output - What am I doing wrong?
The same code worked fine for me!!
But I got the same error you were talking about before I set the File path correctly
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Aug 21st, 2007, 07:46 PM
#3
Thread Starter
New Member
Re: [2.0] Redirecting Output - What am I doing wrong?
I may have gotten a new clue.
I continued on with the project since getting the output was an important but not critical issue. I used the C program to output files, then moved the files it created to a new location. I noticed that the move was failing; several of the files remained in their default location (I used a if !File.Exists(...)). So it seemed to me that the process.WaitForExit wasn't working as I expected. I put
Code:
while (!test.HasExited())
System.Threading.Thread.Sleep(100);
in after the test.Start() and the output redirect. It seems to have worked for the file move problem, but I'm still not getting any redirected output.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|