java.io.IOException: Cannot run program error=2, No such file or directory

拥有回忆 提交于 2019-12-05 02:21:22

Looks like it is similar to the problem I faced, when invoking a shell script (contains system & user created commands) from autosys [autosys -> shell -> Java -> ProcessBuilder]
ProcessBuilder will from a command and execute in Linux machine.
This worked when i log in to Linux box and execute the script but it didn't work when i invoke from autosys.
The actual problem is $PATH variable, which is not being set with the directory of the user created command.
I echo the $PATH variable when executing from Linux machine and Autosys in the shell script, $PATH variable is not set properly when executing from Autosys , after appending user command path to the $PATH variable it worked.
which (cmd) will return the directory of the command, append this directory with $PATH then it will work.

Try adding your script path to $PATH and execute from your application

On unix-like systems, the shell only executes programs residing in the current directory if given an unambiguous path to it. This is to prevent an attacker from, say, putting a program named ls in your home directory which would execute instead of the actual ls program residing in /bin/ls. Thus, the current directory is excluded from the PATH.

Also, try moving

int exitVal=process.waitFor();

to above the while loop.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!