473,382 Members | 1,380 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,382 software developers and data experts.

External Process will not end correctly

Hi Guys,

I am trying to caputre the output for an external application. The idea is
to use the System.Diagnostics.Process to run the exe in a process and
redirect the output to a string.

When I run the external command it works fine. But when i wrap it in a .net
exe it fails to exit and the application does not exit. If I kill the
external exe from task manager, the .net wrap completes.

If I proc.StartInfo.UseShellExecute to true, i can get the external
application to run, but then i lose the output.

Here is a snippet of the code.

static void Main(string[] args)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.FileName=@"C:\Program.exe";
proc.StartInfo.Arguments="";
proc.Start();
proc.WaitForExit();
string stdoutput = proc.StandardOutput.ReadToEnd();
string stderror = proc.StandardError.ReadToEnd();
Console.WriteLine (stdoutput);
Console.WriteLine (stderror);
}

Cheers

Craig.
Jan 9 '07 #1
1 2300
Hi guys,

Got it working, just had to move the proc.WaitForExit(); line to below the
read lines.

Cheers

Craig.

"Craig" wrote:
Hi Guys,

I am trying to caputre the output for an external application. The idea is
to use the System.Diagnostics.Process to run the exe in a process and
redirect the output to a string.

When I run the external command it works fine. But when i wrap it in a .net
exe it fails to exit and the application does not exit. If I kill the
external exe from task manager, the .net wrap completes.

If I proc.StartInfo.UseShellExecute to true, i can get the external
application to run, but then i lose the output.

Here is a snippet of the code.

static void Main(string[] args)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.FileName=@"C:\Program.exe";
proc.StartInfo.Arguments="";
proc.Start();
proc.WaitForExit();
string stdoutput = proc.StandardOutput.ReadToEnd();
string stderror = proc.StandardError.ReadToEnd();
Console.WriteLine (stdoutput);
Console.WriteLine (stderror);
}

Cheers

Craig.
Jan 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bruce Arp | last post by:
I am in need of a little help with a form post. What I need to do is this: 1. Post a couple values to an external website form. 2. External website will process the values posted and if...
4
by: My SQL | last post by:
Hi Can I trigger an external program to run when a new record is added to the mysql table? The external program is in C and instead of scanning the table continuously for new insertions, it...
0
by: lcifers | last post by:
I have written an application and tested it as a Windows executable. It works fine. The application uses an external COM application to process some existing files. But I can't seem to start that...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
1
by: Marcel | last post by:
Hi, I used the following code Jochen Kalmbach suggested to run an external program: System::Diagnostics::ProcessStartInfo *si = new System::Diagnostics::ProcessStartInfo();...
1
by: steveBelfast | last post by:
Having trouble installing my 180 day Visual Studio 2005 trial disk. The CD that was sent is actually a DVD not a CD. My home PC only has a CD drive. I attempted to install on an external drive...
1
by: david.sargent | last post by:
I have a C# program launching an external process, say notepad. I have the process hidden from the user, and want to be able to take screenshots of the hidden program. I have searched around and...
2
by: holysmokes99 | last post by:
I am developing a component in .Net 1.1, and want to debug it using the "start external program" of the debugger in the IDE. The program I want to start references both 1.1 and 2.0 components. The...
3
by: lookaround | last post by:
Hi everyone, I need some help... I call an external exe (a command-line tool) with Process.Start through this code: try { p = new Process(); p.StartInfo.UseShellExecute = false;...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.