RLe
RLe

Reputation: 486

How to pass getopts argurements to a shell script using java

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

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201439

Each argument is a separate String. Like,

String[] args = { "script.sh", "-l", "01", "-n", "02" };

Upvotes: 2

Related Questions