Capturing output from external process

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top