通过批处理脚本(Windows命令行)执行参数化的.exe文件
问题描述:
我试图通过Windows上的命令行脚本(批处理文件)执行.exe文件。实际上,我的脚本在执行文件之前做了很多事情(生成XML配置文件等),然而,这些部分工作得很好,所以我只关注脚本的非工作部分。通过批处理脚本(Windows命令行)执行参数化的.exe文件
我认为执行.exe文件的命令中的空格可能是错误的来源。但是,当用" "
包围该行时,它仍然不起作用。
回声线只适用于" "
(这就是为什么我猜测空间或可能是某些特殊字符或什么导致此问题?)所包含的行。它回声的路径是正确的(通过复制&粘贴到资源管理器中检查,应用程序启动正确)。
这里的错误消息:the filename directory name or volume label syntax is incorrect
和相关的代码片段:
rem Start .exe file with parameters
@echo off
setlocal
rem List of keydates
set "list=20131231 20121231 20111231 201"
set "appPath=C:\Program Files (x86)\xxx\yyy\"
set "configPath=C:\Users\username\Desktop\batch test\"
rem [...] more vars here
for %%i in (%list%) do (
(
rem [...]
rem Generation of XML file, works just fine
rem [...]
)>BatchConfigTest_%%i.xml
rem Batch file is located in config path, this is why I define no explicit path here
)
rem Problem is located here
rem How do I execute the exe correctly? This approach doesn't work
for %%i in (%list%) do (
%appPath%ApplicationXYZ.exe -xmlcommandconfig:"%configPath%BatchConfigTest_%%i.xml
rem echo "%appPath%ApplicationXYZ.exe -xmlcommandconfig:"%configPath%BatchConfigTest_%%i.xml""
rem Echo shows correct paths. Copying the paths from the command line and pasting them into the explorer works.
)
pause
答
它出现的问题是这一行:
%appPath%ApplicationXYZ.exe -xmlcommandconfig:"%configPath%BatchConfigTest_%%i.xml
这将扩大到C:\Program Files (x86)\xxx\yyy\ApplicationXYZ.exe
(没有引号)所以C:\Program
将尝试执行(不存在)。此外,配置XML文件缺少结束语。
尝试更新上面的线:
"%appPath%ApplicationXYZ.exe" -xmlcommandconfig:"%configPath%BatchConfigTest_%%i.xml"
通过将引号将EXE路径,它将扩大到"C:\Program Files (x86)\xxx\yyy\ApplicationXYZ.exe"
(带引号),所以它应该被正确地拾起。此外,我最后在XML路径中添加了一个结束语。
谢谢,就是这么做的。 – daZza 2014-12-09 15:46:19