1

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.

  • what happens when you run the command directly in a prompt? – Leonel Martins Jul 24 '09 at 18:34
2

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

  • my bad, read it as process = Runtime.getRuntime(). exec (new String[] {"/bin/sh","-c" "java OcwCommon.OcwProcessController" + " " +action+ " " +Id); The query still stands.. – harshildesai Jul 24 '09 at 17:00
  • the only thing I can see is the missing + between " -c" and " java – stuart Brand Jul 24 '09 at 19:12
0

Query updated

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.

  • you should edit the post and not add a answer. – Leonel Martins Jul 24 '09 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy