说我有一个名为check.bat的批处理文件。我正在使用命令在Java上运行它
Runtime.getRuntime().exec("cmd /c start C:\\check.bat");
它运行批处理文件没有问题。但是当我像这样将参数传递给批处理文件时,
Runtime.getRuntime()。exec(“ cmd / c start C:\ check.bat arg1 arg2 arg3 arg4”);
我想在check.bat中访问这些参数,我知道%*为我提供了所有参数。但是我想要的是除最后一个参数以外的所有参数作为单个变量。批处理文件非常新。请帮忙。
SomethingDark建议的第一种方法(在调用批处理文件之前组合参数)可能是最好的方法,但是如果您无法使用它,则下面的方法可能会有所帮助(如果您的参数包含具有Windows的特殊含义):
@echo off
setlocal
set ALLBUT1=
if "%~2" == "" goto :gotthem
set ALLBUT1=%1
:loop
shift
if "%~2" == "" goto :gotthem
set "ALLBUT1=%ALLBUT1% %1"
goto :loop
:gotthem
set "LAST=%1"
echo All-but-one:%ALLBUT1%:
echo Last:%LAST%:
这使:
S:\>arg one two three
All-but-one:one two:
Last:three:
S:\>arg one two three four
All-but-one:one two three:
Last:four:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句