![](/img/trans.png)
[英]starting a windows executable via batch script, exe not in Program Files
[英]Executing parameterized .exe files via batch script (Windows command line)
我試圖通過Windows上的命令行腳本(批處理文件)執行.exe文件。 實際上我的腳本在執行文件之前做了很多事情(生成XML配置文件等),然而,這些部分工作得很好,所以我將專注於腳本的非工作部分。
我認為執行.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 20101231"
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路徑中添加了一個結束語。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.