我試圖通過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
謝謝,就是這麼做的。 – daZza 2014-12-09 15:46:19