0

I need to call shell script from java program .I'm trying to use below code but it is not working -

        ProcessBuilder pb = new ProcessBuilder("/bin/bash","/usr/local/bin/ticketer/ticketer_robot");
        pb.environment().put("$1", "test");
        pb.environment().put("$2", "testoce");
        pb.environment().put("$3", "2 - Medium");
        pb.environment().put("$4", "2 - Medium");
        pb.environment().put("$5", "Error while reading file");
        pb.environment().put("$6", "Error While reading file in Job . Please check log NotfnLOG for more details");
        pb.environment().put("$7", "testtestets");
        pb.environment().put("$8","testtesttest");
        pb.environment().put("$9", "/data/mars/logs/tesst.log");
        pb.environment().put("$10", "[email protected]");
        final Process process = pb.start();

Below is command which we are using to invoke script from unix shell -

sh /usr/local/bin/ticketer/ticketer_robot "test" "testoce" "2 - Medium" "2 - Medium" "Error while reading file" "Error While reading file in Job. Please check log for details"
 "testtestets" "testtesttest" "/data/mars/logs/tesst.log" "[email protected]"
4
  • you missed quotes in this line? pb.environment().put("$8",testtesttest); Commented Dec 10, 2015 at 14:16
  • sorry , it was typo in question . for actual call , i'm using quote .. Commented Dec 10, 2015 at 14:17
  • and what is not working? Stacktrace? Commented Dec 10, 2015 at 14:18
  • not getting any error . this script need to update log file but I do not see change in log file when I run this java program . So shell script is not getting called from java .. Commented Dec 10, 2015 at 14:20

1 Answer 1

3

you should not put the arguments of the bash script in environment (thats is for environemntal variables), instead try this:

String[] command = {"/bin/bash",
                    "/usr/local/bin/ticketer/ticketer_robot", 
                    "test",
                    "testoce",
                    "2 - Medium",
                    "2 - Medium",
                    "Error while reading file",
                    "Error While reading file in Job . Please check log NotfnLOG for more details",
                    "testtestets",
                    "testtesttest",
                    "/data/mars/logs/tesst.log",
                    "[email protected]"
};

ProcessBuilder pb = new ProcessBuilder(command);
pb.start();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.