Java – Runtime.getRuntime().exec(String) fails to create a new process | Java + LINUX

java

I am stuck with an issue regarding the failure of Runtime.getRuntime().exec(String) that creates a new process in our application. Though this code worked successfully on the sun system (java 1.4, tomcat 4.0) it does not seem to work at all on Linux. The configurations on linux system are

  • Linux: Fedora 10, Java version: 1.6, Tomcat version: 5.5

Here is the code snippet that runs TestProcess class as a new process:

    process = Runtime.getRuntime().
               exec (new String[] {"/bin/sh","-c",
                 "java OcwCommon.OcwProcessController" + " " +action+ " " +Id);

The ‘process’ variable does not return a null. And no logs are created for the new process. Hence we assume that it is not getting executed.

i am running tomcat with fsuser and i have added classpath, path etc env variables in /etc/profile file. So it gets loaded whenever system boots.

Can there be any authorization issue in creating a new process? Though we have double checked it.

Any pointers would be much appreciated.

Best Answer

Why are you running it twice? I think the line should be as follows

String[] cmd = "/bin/sh","-c", "java OcwCommon.OcwProcessController" + " " +action+ " " +Id;

process = Runtime.getRuntime().exec(cmd);

Stuart

Related Topic