this is my first question here so I\'ll be as detailed as I can. I am currently working on a C# program (We\'ll call it TestProgram) that tests a different program written i
I think the problem is in your C program, not in your C# program. When you produce your output, you do not put \n
at the end. Hence StandardOutput.ReadLine()
will wait forever, because there is no end-of-line marker in the stream.
Since the output of your C program is used to synchronize the steps of your co-operating programs, it is also a very good idea to flush it to the output before waiting for the next portion of input:
printf("%s\n", result);
fflush(stdout);
Your C# code seems to be just fine, I tried it with another C# program:
static void Main(string[] args)
{
String line = Console.ReadLine();
Console.WriteLine("I received " + line);
}
And the following code outputs "I received Hello world!". So the problem must be in your C code. As dasblinkenlight already mentioned, new line symbols might be missing.
static void Main(string[] args)
{
Process cmd = new Process();
ProcessStartInfo info = new ProcessStartInfo(@"AnotherApp.exe", "");
info.WorkingDirectory = @"path\to\folder";
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.UseShellExecute = false;
cmd.StartInfo = info;
cmd.Start();
cmd.StandardInput.WriteLine("Hello world!");
String output = cmd.StandardOutput.ReadLine();
Console.WriteLine(output);
Console.ReadKey();
}