471,337 Members | 805 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Program started via System.Diagnostics.Process hangs

Hello folks,

I'm using System.Diagnostics.Process to start a thirdparty program
(that works perfectly when started via command line). I'm using
Process.StandardOutput to get the output of the program. That works
for 95 %, but the other 5 % it doesn't. It seems to me that the
started process just hangs, and therefor my program hangs, too
(p.WaitForExit()). I researched that this only happens when the output
of the program is longer than 4096 bytes: I killed the hung process,
WaitForExit returns and in StandardOutput is a string with a length of
4096 chars. The returned string contains the expected output of the
program, but is shortened to 4 KB.

Does somebody know why it hangs and how to fix this problem?

I'm using this code here:

static string GetProcessOutput(string cmd, string args, out string
error)
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = new System.Diagnostics.ProcessStartInfo(cmd, args);
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
p.PriorityClass = System.Diagnostics.ProcessPriorityClass.High;
p.WaitForExit();

string output = p.StandardOutput.ReadToEnd();
error = p.StandardError.ReadToEnd();

return output.Trim();
}

Thanks in advance,

Benny Fischer.

Sep 25 '07 #1
2 6645
Hi,

Remove the wait for exit and all other members, then it will works
perfectly as when started via command line as you wrote.

Cor

<te***@twinmail.deschreef in bericht
news:11**********************@r29g2000hsg.googlegr oups.com...
Hello folks,

I'm using System.Diagnostics.Process to start a thirdparty program
(that works perfectly when started via command line). I'm using
Process.StandardOutput to get the output of the program. That works
for 95 %, but the other 5 % it doesn't. It seems to me that the
started process just hangs, and therefor my program hangs, too
(p.WaitForExit()). I researched that this only happens when the output
of the program is longer than 4096 bytes: I killed the hung process,
WaitForExit returns and in StandardOutput is a string with a length of
4096 chars. The returned string contains the expected output of the
program, but is shortened to 4 KB.

Does somebody know why it hangs and how to fix this problem?

I'm using this code here:

static string GetProcessOutput(string cmd, string args, out string
error)
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = new System.Diagnostics.ProcessStartInfo(cmd, args);
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
p.PriorityClass = System.Diagnostics.ProcessPriorityClass.High;
p.WaitForExit();

string output = p.StandardOutput.ReadToEnd();
error = p.StandardError.ReadToEnd();

return output.Trim();
}

Thanks in advance,

Benny Fischer.

Sep 25 '07 #2
On 25 Sep., 13:03, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
Hi,

Remove the wait for exit and all other members, then it will works
perfectly as when started via command line as you wrote.

Cor
Thanks for your help Cor, it works perfectly now!

Greetings,
Benny

Sep 25 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Ed Bitzer | last post: by
1 post views Thread by wmotter | last post: by
reply views Thread by jdrott1 | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.