2014-12-09 132 views
1

我試圖通過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 

回答

3

它出現的問題是這一行:

%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路徑中添加了一個結束語。

+0

謝謝,就是這麼做的。 – daZza 2014-12-09 15:46:19

相關問題