我知道这个问题看起来很傻,但我很难运行.bat文件。我有一个.bat文件位于下面的路径。 C:\实时数据导出工具\ ExportTool \ BatchFiles 注意Root文件夹中的空格。 我试图直接运行.bat文件,前缀如下:
C:\Realtime Data Export Tool\ExportTool\BatchFiles\ExportData.bat "DNCORR" "SYSTEM" "SYSTEM123" "SYNC" "TEST"
我收到以下错误:
' C:\实时'不被视为内部或外部命令, 可操作程序或批处理文件。
我不想做" CD FolderPath"然后运行ExportData.bat。实际要求是我必须从HTML页面运行Windows命令。 Javacsript构造此字符串并打开commandpromt以运行批处理文件。所以我希望在单个命令中完成此操作,其中包括.bat文件的完整路径。 有人可以帮忙吗?
答案 0 :(得分:2)
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
==>
资源(必读):
答案 1 :(得分:0)
我找到了解决方案。我正在工作。我应该构造命令字符串,如:
cd C:\Realtime Data Export Tool\ExportTool\BatchFile & ExportData.bat "DNCORR" "SYSTEM" "SYSTEM123" "SYNC" "TEST"
感谢您的帮助。
答案 2 :(得分:0)
您只需要在批处理文件的路径和文件名周围添加引号...如果需要,请在参数周围保留引号。
"C:\Realtime Data Export Tool\ExportTool\BatchFiles\ExportData.bat" "DNCORR" "SYSTEM" "SYSTEM123" "SYNC" "TEST"