bat默认只能获取到1-9个参数,分别用%1 %2 ... %9引用,如果传给bat的参数大于9个,就必须用shift。

工作需要,要写个bat脚本,获取所有的参数,再将所有的参数传给Java,代码如下:

allparam就是获取到的所有参数字符串。

@echo off

set java=.\jre1.8.0_102\bin\java.exe
set jarpath=.\lib\xx.jar

set allparam=

:param
set str=%1
if "%str%"=="" (
    goto end
)
set allparam=%allparam% %str%
shift /0
goto param

:end
if "%allparam%"=="" (
    goto eof
)

rem remove left right blank
:intercept_left
if "%allparam:~0,1%"==" " set "allparam=%allparam:~1%"&goto intercept_left

:intercept_right
if "%allparam:~-1%"==" " set "allparam=%allparam:~0,-1%"&goto intercept_right

:eof
%java% -jar %jarpath% %allparam%

pause

 

相关文章:

  • 2022-12-23
  • 2021-04-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2021-11-03
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案