编辑 - 解决方案:
C:\Realtime Data Export Tool\ExportTool\BatchFiles\ExportData.bat "DNCORR" "SYSTEM" "SYSTEM123" "SYNC" "TEST"
... Javacsript 构造此字符串并打开 commandpromt 以运行
批处理文件...
换句话说,它必须调用cmd /C 或cmd /K 来打开命令提示符......在你的情况下:
cmd /C "C:\Realtime Data Export Tool\ExportTool\BatchFiles\ExportData.bat" "DNCORR" "SYSTEM" "SYSTEM123" "SYNC" "TEST"
不起作用,帮助 (cmd /?) 解释说,在这种情况下,第一个和最后一个引号被删除。因此,您的字符串可以是以下任何一种(不是详尽的列表,还有其他)使用:
- 附加引号
""C:\Realtime Data Export Tool\ExportTool\BatchFiles\ExportData.bat" "DNCORR" "SYSTEM" "SYSTEM123" "SYNC" "TEST""
- 替代引用
C:"\Realtime Data Export Tool\ExportTool\BatchFiles\ExportData.bat" "DNCORR" "SYSTEM" "SYSTEM123" "SYNC" "TEST"
-call command(首选)
call "C:\Realtime Data Export Tool\ExportTool\BatchFiles\ExportData.bat" "DNCORR" "SYSTEM" "SYSTEM123" "SYNC" "TEST"
- @ 符号
@"C:\Realtime Data Export Tool\ExportTool\BatchFiles\ExportData.bat" "DNCORR" "SYSTEM" "SYSTEM123" "SYNC" "TEST"
证明:
==>type "simple cli Parser.bat"
@echo %%* = %*
==>"simple cli Parser.bat" "aa" bb
%* = "aa" bb
==>cmd /C "simple cli Parser.bat" "aa" bb
'simple' is not recognized as an internal or external command,
operable program or batch file.
==>cmd /C ""simple cli Parser.bat" "aa" bb"
%* = "aa" bb
==>cmd /C simple" cli Parser.bat" "aa" bb
%* = "aa" bb
==>cmd /C call "simple cli Parser.bat" "aa" bb
%* = "aa" bb
==>cmd /C @"simple cli Parser.bat" "aa" bb
%* = "aa" bb
==>
原答案:
尝试下一批,看看参数是如何工作的:
@echo OFF >NUL
echo(
echo before any shift [%~1] [%~2] [%~3] [%~4]
echo all %%* = %*
echo(
set /A "ii=0"
:loopfor
echo param %%%ii% = %0
SHIFT
set /A "ii+=1"
if not [%0]==[] goto :loopfor
echo(
echo after all shifts [%~1] [%~2] [%~3] [%~4]
echo all %%* = %*
输出:
==>"D:\bat\cli Parser.bat" "a string with spaces" stringwithout spaces
before any shift [a string with spaces] [stringwithout] [spaces] []
all %* = "a string with spaces" stringwithout spaces
param %0 = "D:\bat\cli Parser.bat"
param %1 = "a string with spaces"
param %2 = stringwithout
param %3 = spaces
after all shifts [] [] [] []
all %* = "a string with spaces" stringwithout spaces
==>
资源(必读):