如何将参数传递到批处理文件?

时间:2022-07-20 16:37:45

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

如何使用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");****

****进程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.

当我使用这个编码时会发生错误。参数是最后三部分。补丁文件是RMIClientInvoker.bat。我尝试在命令行中出现相同的错误,但我把双Qoutes放到参数正确的o / p display.so任何一个帮助如何给参数doubleQoutes。

1 个解决方案

#1


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:

失败的原因是运行时exec按空格分割参数(与调用Main方法时java的方式相同)。引用参数确保它将整个C:\ Program Files \ Apache Group \ Tomcat 4.1 \ bin \ RMIClientInvoker.bat视为单个参数,并且不认为它是一组四个参数:

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

#1


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:

失败的原因是运行时exec按空格分割参数(与调用Main方法时java的方式相同)。引用参数确保它将整个C:\ Program Files \ Apache Group \ Tomcat 4.1 \ bin \ RMIClientInvoker.bat视为单个参数,并且不认为它是一组四个参数:

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