Reputation: 486
I want to run a shell script using java using Runtime.getRuntime().exec()
. However, my shell script is using getopts so I need to use this command in terminal to run the script:
./script.sh -l 01 -n 02
So how can i execute this script with multiple args using java? I tried the bellow code but I does not work.
String[] args = {"script.sh", "-l 01", "-n 02"};
Runtime.getRuntime().exec(args);
Upvotes: 1
Views: 144
Reputation: 201439
Each argument is a separate String
. Like,
String[] args = { "script.sh", "-l", "01", "-n", "02" };
Upvotes: 2