Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Running a .bat file
Message
 
À
09/07/2004 08:44:55
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00922451
Message ID:
00922455
Vues:
12
>Hello,
>I am running a .bat file in my application using the code: System.Diagnostics.Process.Start("c:\test.bat")
>
>I am wanting the application to stop until this .bat file is completely done. How can I do that? Thanks!!
>
>MAC


From an article I wrote in the UTMag (December 2003):

Wait for a launched process to end

This is a very frequent requirement. You want to start a process from your application, let it do its task and close, all this while your application is waiting for the launched process to stop before continuing.

As you will soon discover, the Process component makes it really (once again) simple!

Using the same code we already used to start the Notepad, we can simply add the call to the WaitForExit method to wait for the process to close before continuing (displaying the message box in my sample):

MyProcess.StartInfo.FileName = "notepad.exe"
MyProcess.StartInfo.WorkingDirectory = "c:\temp"
MyProcess.StartInfo.Arguments = "Test.txt"
MyProcess.Start()

MyProcess.WaitForExit()
MessageBox.Show("It was time!!!", "Process has now exited")

There is an overload to the WaitForExit method that accepts a number of milliseconds to wait. I strongly recommend that you look at this alternative because we never know if the process will be launched and closed correctly!
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform