Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1011 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to wait until my batch file is finished

#1
I'm doing a program where I need to start cmd and there start up a batch file. The problem is that I'm using `MyProcess.WaithForexit();` and I think it does not wait until the batch file processing is finished. It just waits until the cmd is closed. My code so far:

System.Diagnostics.ProcessStartInfo ProcStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd");
ProcStartInfo.RedirectStandardOutput = true;
ProcStartInfo.UseShellExecute = false;
ProcStartInfo.CreateNoWindow = false;
ProcStartInfo.RedirectStandardError = true;
System.Diagnostics.Process MyProcess = new System.Diagnostics.Process();
ProcStartInfo.Arguments = "/c start batch.bat ";
MyProcess.StartInfo = ProcStartInfo;
MyProcess.Start();
MyProcess.WaitForExit();


I need to wait until the batch file is finished. How do I do that?
Reply

#2

The start command has arguments that can make it `WAIT` for the started program to complete. Edit the arguments as show below to pass '/wait':

ProcStartInfo.Arguments = "/c start /wait batch.bat ";

I would also suggest that you want your batch file to exit the cmd envirionment so place an 'exit' at the end of the batch.

@echo off
rem Do processing
exit

This should achieve the desired behavior.

Reply

#3
This actually worked just fine for me:

System.Diagnostics.Process.Start("myBatFile.bat").WaitForExit();


As milton said, adding 'exit' at the end of your batch files is most likely a good idea.

Cheers

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through