1

I am trying to execute an .exe file via a command line script on Windows (batch file). Actually my script does a lot more before executing the file (generating XML config files and such), however, theses parts work just fine, so I will just concentrate on the non working part of the script here.

I think that the spaces in the command to execute the .exe file might be the source of the error. However, when enclosing the line with " " it still won't work.

Echoing the line only works with the line enclosed by " " (that's why I am guessing that spaces or maybe some special characters or something cause this problem?). The path it echoes is correct though (checked via copy&paste into the explorer. Application started properly).

Here's the error message: the filename directory name or volume label syntax is incorrect

And the relevant code extract:

    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

1 Answer 1

3

It appears the problem is this line:

%appPath%ApplicationXYZ.exe -xmlcommandconfig:"%configPath%BatchConfigTest_%%i.xml

This will expand to C:\Program Files (x86)\xxx\yyy\ApplicationXYZ.exe (no quotes) so C:\Program will attempt to be executed (which doesn't exist). Also the config XML file is missing a closing quote.

Try updating the above line to:

"%appPath%ApplicationXYZ.exe" -xmlcommandconfig:"%configPath%BatchConfigTest_%%i.xml"

By placing quotes around the EXE path, it will expand to "C:\Program Files (x86)\xxx\yyy\ApplicationXYZ.exe" (with quotes) so it should be picked up correctly. Additionally, I added a closing quote to the XML path at the end.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.