-1

Would like to execute selenium script/batch scripts using java. Based on input parameters to call script/batch scripts.

To understand, how to run script/batch using java code.

Please help me out here.

2
  • 2
    Why did you try? Commented Jul 10, 2018 at 7:08
  • Provide some sample code. Commented Jul 10, 2018 at 7:25

1 Answer 1

1

to run a bash script contained in a file in a java project, use the ProcessBuilder class like this:

ProcessBuilder procBuildScript = new ProcessBuilder ([your_script_path],arg1,arg2,...);
procBuildScript.start();

So you can pass arguments after your script path as "script.sh",arg1,arg2

For example :

public void runMyScript(String aFirstArg, String aSecondArg){

     ProcessBuilder procBuildScript = new ProcessBuilder("./your-script.sh",aFirstArg,aSecondArg);
     procBuildScript.start();

}

In your script you can call these arguments using the expressions $ 1, $ 2 ... $ {10}, $ {11} corresponding to the index where the desired parameter is located :

#!/bin/bash
# your-script.sh

echo "First argument is : $1"
echo "Third argument is : $3"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.