tags:

views:

728

answers:

1

how to pass the parameter into batch file using java runtime.exec().

**Process pp = run.exec("C:\Program Files\Apache Group\Tomcat 4.1\bin\RMIClientInvoker.bat C:\Program Files\Apache Group\Tomcat 4.1\bin localhost date");**

when i using this coding error will occur.the parameters are last three part.batch file is RMIClientInvoker.bat. i try in command line the same error has appear but i put the double Qoutes to the parameter the correct o/p display.so any one help how to give the parameter with doubleQoutes.

+1  A: 

Escape the double quotes:

Process pp = run.exec("\"C:\Program Files\Apache Group\Tomcat 4.1\bin\RMIClientInvoker.bat\" \"C:\Program Files\Apache Group\Tomcat 4.1\bin\" localhost date");

The reason this is failing is that runtime exec splits arguments by whitespace (in the same way that java does when you call your Main method). Quoting the arguments ensure that it treats the whole of C:\Program Files\Apache Group\Tomcat 4.1\bin\RMIClientInvoker.bat as a single argument and doesn't think it is a set of four arguments:

  • C:\Program
  • Files\Apache
  • Group\Tomcat
  • 4.1\bin\RMIClientInvoker.bat
butterchicken