When you execute a command from the command line, the shell knows where to find the executable because it has access to the PATH environment variable, which contains a list of directories where executable files are located. However, when running a command from a Java program using Runtime.getRuntime().exec()
, the system might not have access to the same PATH environment variable.
To resolve this issue, you can either provide the full path to the "cf" executable in your Java code, or you can modify the PATH environment variable for the Java process.
Regarding modifying the PATH for the Java process, you can see here a previous SO question.