473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 6837
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dao | last post by:
I have created a windows service called MyService. I followed the MSDN sample code to add the following code but it did not work. What I tried was that to start another or external program when...
4
by: Kristof Despiere | last post by:
Suppose you have one domain, filled with a couple of users. What needs to be done now is I need to start a windows application from a webform by pressing a button on the webform (for example). ...
0
by: wayne hamilton | last post by:
I'm having a problem Interacting with Command Line programs. I can read and write anything I want as long as I don't have to interact with a process once it's started. Originally I had been calling...
17
by: UJ | last post by:
Is there any way for a windows service to start a windows program ? I have a service that will need to restart a windows app if it needs to. TIA - Jeff.
5
by: jmsxp | last post by:
Hi all, I am in my infancy with programming, so please forgive stupid questions... I am attempting to write a C# program that will launch Trillian (well, that is just a part of the overall...
6
by: Ed Bitzer | last post by:
You have taught me how to start another program using System.Diagnostics.Process.Start and suggested a good tip site and Google search for future reference. My problem now is how to stop that...
1
by: wmotter | last post by:
I have a requirement to execute a legacy DOS program from within an ASP.NET Website. I have it working in my sandbox machine but when I put it live and select the option via asp:button the site...
8
by: TxAg03 | last post by:
I ran an outside program that launched another program. I created a process for the launcher program and waited for that to exit, but what I need is to have it wait for the 2nd program to exit. ...
0
by: jdrott1 | last post by:
our business uses modem connections to transmit data back and forth. it uses a third party program to collect all the information. some times this third party application on the remote computer...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.