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

Running and waiting for a program to finish

Hi folks,

I'm writing a program that needs to execute an external program and wait
for it to finish running before it can make use of the output from that
program. Specifically, the external program converts from one file
format to another, and is something that I can't do natively :(

So what I need to figure out is how to:

a) Start the external program, with parameters
b) Wait for the external program to finish
c) Do something with the converted file

Now, step c) is the easy part in that I can do that already, but I'm not
sure how to do steps a) and b).

Any help is appreciated, cheers

--
Dylan Parry - http://electricfreedom.org

Programming, n: A pastime similar to banging one's head
against a wall, but with fewer opportunities for reward.
Jul 26 '06 #1
4 8388
At the simplest level:

using System;
using System.Diagnostics;
class Program
{
static void Main(string[] args)
{
using(Process proc = Process.Start("notepad.exe",@"C:\CONFIG.SYS"))
{
proc.WaitForExit();
// can also now look at proc.ExitCode
}
}
}

Marc
Jul 26 '06 #2
Marc Gravell wrote:
At the simplest level:
[...]

The simplest level is just fine for what I have in mind! Cheers :)

--
Dylan Parry - http://webpageworkshop.co.uk

Programming, n: A pastime similar to banging one's head
against a wall, but with fewer opportunities for reward.
Jul 26 '06 #3
Hi,

Take a look at the Process class and Process.WaitForExit

Also worth of note is that WaitForExit will block the thread, so if you are
running this in a win app it will freeze. so you better do it in a
background thread.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Dylan Parry" <us****@dylanparry.comwrote in message
news:4i************@individual.net...
Hi folks,

I'm writing a program that needs to execute an external program and wait
for it to finish running before it can make use of the output from that
program. Specifically, the external program converts from one file
format to another, and is something that I can't do natively :(

So what I need to figure out is how to:

a) Start the external program, with parameters
b) Wait for the external program to finish
c) Do something with the converted file

Now, step c) is the easy part in that I can do that already, but I'm not
sure how to do steps a) and b).

Any help is appreciated, cheers

--
Dylan Parry - http://electricfreedom.org

Programming, n: A pastime similar to banging one's head
against a wall, but with fewer opportunities for reward.

Jul 26 '06 #4
Ignacio Machin ( .NET/ C# MVP ) wrote:
Take a look at the Process class and Process.WaitForExit
Yes, thanks, that's the solution recommended by another posted too.
Also worth of note is that WaitForExit will block the thread, so if you are
running this in a win app it will freeze. so you better do it in a
background thread.
Ok, but in my case it won't matter as the program isn't a windows app,
but something running in the background on a server. Thanks for the
warning though - I might have to create a win app at some point that
does something similar.

--
Dylan Parry - http://electricfreedom.org

Programming, n: A pastime similar to banging one's head
against a wall, but with fewer opportunities for reward.
Jul 26 '06 #5

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

Similar topics

0
by: Fuzzyman | last post by:
I've written an an anagram generator. (The desktop version is available for download from http://www.voidspace.org.uk/atlantibots/nanagram.html !!) The CGI version is at :...
17
by: los | last post by:
Hi, I'm trying to create a program similar to that of Google's desktop that will crawl through the hard drive and index files. I have written the program and as of now I just put the thread to...
10
by: MikeE | last post by:
Hi all, What's the best way to queue up and wait for number of threads to complete. This problem was trivial in VC++ 6 but I'm finding it rather hard to solve in VB.NET. My calculations run...
2
by: Steve W | last post by:
Is it possible to keep some communication going between the browser and web server going while waiting for a long running process to finish ? We have one function on our app (ASP.NET / VB.NET)...
4
by: hplloyd | last post by:
Hi I want my VB.NET application to run a command from the command line and then wait for the command to finish before continuing. I am currently using System.Diagnostics.Process.Start(strApp) ...
6
by: Hugh Janus | last post by:
Hi group, I am executing a shell command that calls a .BAT file. I have to wait for this batch file to finish so I use the wait = true parameter in the shell command. However, this means that...
2
by: Paul Rubin | last post by:
I have a long-running program that has lots of net connections open on separate threads. I'm twiddling my thumbs waiting for it to finish (each run takes maybe an hour) and although I'm logging...
1
by: Simon_21 | last post by:
Hi All, I have a servlet which is invoked from a jsp page. While the serlvet is executing, the jsp page is waiting for the servlet to complete. When the servlet completes, it informs the waiting...
9
by: erikcw | last post by:
Hi, I have a cgi script where users are uploading large files for processing. I want to launch a subprocess to process the file so the user doesn't have to wait for the page to load. What is...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.