I have a Java program that runs a batch file on Windows with Runtime.getRuntime().exec()
using the following command:
cmd /C start "Title" "C:\Folder\file.bat"
The Java program ends quickly since cmd /C
carries out the command and then terminates (1) and start "Title" "C:\Folder\file.bat"
starts the batch script (2). Thus the process (the batch file) will continue running independently.
Now, suppose that I have an shell script (e.g. file.sh
), which I want to launch from Java and has a similar behavior. How could it be the equivalent command (3) in Linux?
Notes
- See CMD.exe (Command Shell) | Windows CMD | SS64.com
- See Start - Start a program | Windows CMD | SS64.com
- The title (
"Title"
) is not required.
Runtime.getRuntime().exec()
, and Java being cross-platform language would use same method to launch a program. The post isn't about running scripts form desktop either - it's running scripts in general, and the key to that making script executable withchmod +x
and giving path to script or at least having script live in one of the directories that belong toPATH
variable. Whether or not it's form Java is irrelevant. These steps are required – Sergiy Kolodyazhnyy Apr 05 '17 at 22:21