Link to home
Start Free TrialLog in
Avatar of brian_s
brian_s

asked on

Runtime.exec from a servlet ?

can Runtime.exec be run from a servlet?
Avatar of bagi112599
bagi112599

yes, I think so.
Avatar of brian_s

ASKER

it works fine when i do:

javac Example.java
java Example

however from a servlet it doesn't work
Avatar of brian_s

ASKER

if i cut and paste the command string from my java program and paste it into the dos prompt it works fine-

so something is going wrong from servlet to cmd line execution

please help
Avatar of brian_s

ASKER

if i cut and paste the command string from my java program and paste it into the dos prompt it works fine-

so something is going wrong from servlet to cmd line execution

please help
Avatar of brian_s

ASKER

if i cut and paste the command string from my java program and paste it into the dos prompt it works fine-

so something is going wrong from servlet to cmd line execution

please help
Avatar of Mick Barry
Running a command from the command line, is not the same as running it from exec.
The problems probably because of an environement difference.
Ensure you include the full pathname of the executable you are trying to run, and that you supply all the required environment variables.

Or run your command with the command shell.
Avatar of brian_s

ASKER

I have it running from the exec if I just invoke that class...

javac whatever.java
java whatever

and it'll work just fine


However, the same exec code through a servlet doesn't work.  No errors are generated!?

I'm using Websphere v3.52 on NT

thanks
Again the servlet runs in a different environment than what your user login does.
What's the error your getting?
Avatar of brian_s

ASKER

I'm not getting any errors, but the process's exitCode() is returning 1 if that helps.


Sorry it took so long for me to get back to this... I tried to get in but Experts was down-

If I watch the task manager on the NT box while I click on the link in my servlet, I first see a CMD.EXE start than a JAVA.EXE

so it seems as if they are both starting, just not properly finishing

any ideas
Avatar of brian_s

ASKER

here is some of my code if it helps:



Runtime RunTime = Runtime.getRuntime();
      Process process = null;
      String  dir = "c:\\websphere\\appserver\\hosts\\default_host\\ias\\java_source\\",
              swfName = dir + ProjectId,
              template = dir + "one.swt",
              myExe;
      try{  
         myExe = "cmd /c c:\\jgenerator-1.3.0\\bin\\jgenerate.cmd -param projectName " + "\"" + ProjectName + "\"" +
                                                         " -param sectionOne "+ "\"" + sectionOne + "\"" +  
                                                         " -param sectionTwo "+ "\"" + sectionTwo + "\"" +
                                                         " -param sectionThree "+ "\"" + sectionThree + "\"" +  
                                                         " -param sectionFour "+ "\"" + sectionFour + "\"" +
                                                         " -param sectionFive "+ "\"" + sectionFive + "\"" +
                                                         " -param sectionSix "+ "\"" + sectionSix + "\"" +
                                                         " -param paragraphOne "+ "\"" + paragraphOne + "\"" +
                                                         " -param paragraphTwo "+ "\"" + paragraphTwo + "\"" +
                                                         " -param paragraphThree "+ "\"" + paragraphThree + "\"" +
                                                         " -param paragraphFour "+ "\"" + paragraphFour + "\"" +
                                                         " -param paragraphFive "+ "\"" + paragraphFive + "\"" +
                                                         " -param paragraphSix "+ "\"" + paragraphSix + "\"" +
                                                         " -swf " + swfName + ".swf " + template;
         System.err.println(myExe);
         
         process = RunTime.exec(myExe);
       
         System.err.println("got here also.... process = " + process);
      try {
         int rc = process.waitFor();
       }
       catch (InterruptedException ie) {
        System.err.println(ie);
      }
      System.out.println("process returned " + process.exitValue());
         process.destroy();
      }
      catch (IOException e){  
           System.err.println("_DbFlash CreateSWF failed! IOException...   stacktrace-->");
           e.printStackTrace();
      }



NO exceptions are thrown.....
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brian_s

ASKER

hello objects.. just logged in to this site for the first time in a while


although i never figured this out (did it through a workaround)... you did help alot so here's the points
Thanks.