javaprocessruntime.execprocessbuilder

Process builder returns exit code 127 when running a Kshell script


I am trying to run a Kshell script via Java process builder. The script itself works perfectly when run on the server. However, when I run it via process builder I am getting exit code 127 - command not found.

Code:

ProcessBuilder procBuilder = new ProcessBuilder(command);
procBuilder.directory(new File(codeDir));
proc = procBuilder.start();
errorCode = proc.waitFor();

return errorCode;

My command look like:

[/bin/ksh, -c, myscript.ksh, 20150714]

I run the script on the server by itself using following command:

ksh -x myscript.ksh 20150714

any idea what is going on wrong here?


Solution

  • Gave up on procesbuilder and tried common-exec and it worked perfectly. Here is my updated code:

    CommandLine cmdLine = CommandLine.parse(command);
    
    for (String comm : cmd)
    {
        cmdLine.addArgument(comm);
    }
    
    DefaultExecutor exec = new DefaultExecutor();
    exec.setExitValue(0);
    exec.setWorkingDirectory(new File(codeDir));
    exitCode = exec.execute(cmdLine);
    

    Hope it help someone in the future.