I'm trying to execute a command via command-line and afterwards execute another command (not in cmd) which dependes on the outcome of the former command. The problem is that the first command takes about 2 minutes to end, and the 2nd command won't "wait" for the first one to end. How can I hold the 2nd command to wait until the first ends?
Thanks in advance!
public void runCmd(){ String command = @"/k java -jar myJava.jar"; ProcessStartInfo cmdsi = new ProcessStartInfo("cmd.exe"); cmdsi.Arguments = command; Process cmd = Process.Start(cmdsi); } . . . runCmd(); //first command, takes 2 minutes to finish MessageBox.Show("This Should popup only when runCmd() finishes");
Enter the CLI command. By default, only one command can be executed at one time. Tip: To bulk execute CLI commands, select Batch CLI, and click the icon to select Load CLI Templates. You can also create your own template, or select each device entry in the action panel to add or remove specific commands.
Press Windows+R to open “Run” box. Type “cmd” and then click “OK” to open a regular Command Prompt. Type “cmd” and then press Ctrl+Shift+Enter to open an administrator Command Prompt.
EXECUTE forces the data to be read and executes the transformations that precede it in the command sequence.
Use the Process.WaitForExit Method:
public void runCmd() { String command = @"/k java -jar myJava.jar"; ProcessStartInfo cmdsi = new ProcessStartInfo("cmd.exe"); cmdsi.Arguments = command; Process cmd = Process.Start(cmdsi); cmd.WaitForExit(); } . . . runCmd(); MessageBox.Show("This Should popup only when runCmd() finishes");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With