Capturing output from external process

  • Thread starter Thread starter Marcel
  • Start date Start date
M

Marcel

Hi,

I used the following code Jochen Kalmbach suggested to run an external
program:

System::Diagnostics::ProcessStartInfo *si = new
System::Diagnostics::ProcessStartInfo();
si->UseShellExecute = false;
si->WorkingDirectory = S"D:\\Promela\\";
si->FileName = "D:\\Promela\\PAN.exe";
si->Arguments = "-a -v";
si->CreateNoWindow = true;
si->RedirectStandardOutput = true;
System::Diagnostics::Process *p =
System::Diagnostics::Process::Start(si);
System::String *output = p->StandardOutput->ReadToEnd();
p->WaitForExit();
System::Windows::Forms::MessageBox::Show(output);

The problem is that the string output is empty, while I know there is
output produced. I think the problem may be that the StandardOutput is
read before the output is produced, though I'm not sure. I tried
switching the oreder of the ReadToEnd() and the WaitForExit line, but
this doesn't help.

Does anyone know how to capture the output correctly?

Thanks in advance,

Marcel
 
Back
Top