I have the following line to run a batch file,
Process process = Runtime.getRuntime().exec("cmd /c start rake.bat");
But I want it to run in the background and not display the command line to the user. How can I change it to do this?
The problem is that the command window opens and intrupts the programs GUI. I just want the command window to not be visible while it is executing the batch file.
The & symbol, switches the program to run in the background. The nohup utility makes the command passed as an argument run in the background even after you log out.
If you want to run additional commands while a previous command runs, you can run a command in the background. If you know you want to run a command in the background, type an ampersand (&) after the command as shown in the following example. The number that follows is the process id.
Removing the 'start' completely will do what you want (as this is what is creating the window):
Process process = Runtime.getRuntime().exec("cmd /c rake.bat");
I have tested this and it works, ofcourse if you want to communicate with the command prompt you'd have to have Input and Output streams, also not forgetting your Error stream As stated in the comment though removing 'start' on XP wont help (as it wont work).
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