473,623 Members | 2,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Diagnost ics.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.Diagnost ics.Process proc = new System.Diagnost ics.Process();
proc.EnableRais ingEvents=false ;
proc.StartInfo. UseShellExecute = false;
proc.StartInfo. CreateNoWindow = true;
proc.StartInfo. RedirectStandar dOutput = true;
proc.StartInfo. RedirectStandar dError = true;
proc.StartInfo. FileName=@"C:\P rogram.exe";
proc.StartInfo. Arguments="";
proc.Start();
proc.WaitForExi t();
string stdoutput = proc.StandardOu tput.ReadToEnd( );
string stderror = proc.StandardEr ror.ReadToEnd() ;
Console.WriteLi ne (stdoutput);
Console.WriteLi ne (stderror);
}

Cheers

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

Got it working, just had to move the proc.WaitForExi t(); 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.Diagnost ics.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.Diagnost ics.Process proc = new System.Diagnost ics.Process();
proc.EnableRais ingEvents=false ;
proc.StartInfo. UseShellExecute = false;
proc.StartInfo. CreateNoWindow = true;
proc.StartInfo. RedirectStandar dOutput = true;
proc.StartInfo. RedirectStandar dError = true;
proc.StartInfo. FileName=@"C:\P rogram.exe";
proc.StartInfo. Arguments="";
proc.Start();
proc.WaitForExi t();
string stdoutput = proc.StandardOu tput.ReadToEnd( );
string stderror = proc.StandardEr ror.ReadToEnd() ;
Console.WriteLi ne (stdoutput);
Console.WriteLi ne (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
1410
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 needed, load an form of its own that the end user will need to enter some info into and submit. 3. External website will post back to a form on my website and I will process and continue with the users session from there.
4
20133
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 will be better if an external program could be triggered. Any suggestions?
0
1344
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 external program correctly. I've found this code: ' Set process parameters Dim myProcess As New System.Diagnostics.Process myProcess.StartInfo.FileName = "notepad.exe" ' Allow the process to raise events
5
3623
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 New System.Diagnostics.Process 'p.Start(MDEPDirStr & "macrun.exe", sPPTOut) p.Start("C:\WINDOWS\SYSTEM32\CALC.EXE") 'p.Start("C:\WINDOWS\SYSTEM32\macrun.exe", sPPTOut)
1
1231
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(); si->UseShellExecute = false; si->WorkingDirectory = S"D:\\Promela\\"; si->FileName = "D:\\Promela\\PAN.exe";
1
1732
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 using a work PC with a DVD drive and then use the external drive from my home PC. Unfortunately the install process puts files on the hard drive of the work PC as well as on the external drive. So I can not run the software from my home PC using the...
1
1307
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 found people using Printwindow() with a pointer to the application, but every time all I get is a black window...anybody know how to do this correctly? Thanks David
2
1758
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 problem is that when I launch this from VS2003, the external program starts only for a moment and then bails out of memory with no error, and the ide returns to a stopped state awaiting my input. If I remove the 2.0 framework, at least the...
3
4165
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; p.StartInfo.FileName = ExePath;
0
8670
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8613
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8326
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6106
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4074
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4164
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1778
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.