开发者

starting a windows executable via batch script, exe not in Program Files

This is probably batch scripting 101, but I can't find any clear explanation/documentation on why this is happening or if my workaround is actually the solution. So basically any terminology or links to good sources is really appreciated.

So I have a program I want to execute via batch script (along with several other programs). It's the only one where the exe is not in a Program Files folder. I can get it to start like this:

C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe

But I get an error along the lines of:

Run-time Error '3024':

Could not find file
C:\Users\MyUserName\Desktop\ModuleSettings.mdb

So it seems that the program is looking for its settings files from the same location that the batch script starts up. Given that I finally got everything to work by doing th开发者_StackOverflowe following:

cd C:\WeirdProgram\WeirdProgramModule\
weirdmodule.exe

That works fine, and it's not the end of the world to have to go this route (just one extra line), but I've convinced myself that I'm doing something wrong based on lack of basic understanding.

Anybody know or can point me to why it works this way?

Oh, and doing the following:

start "C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe"

doesn't do anything at all.

Thanks,


you are doing it perfectly :-)

the executable is probably looking for this file in the "current working directory", which is being set, when you "cd" to it before.

you can set your working directory manually by creating a shortcut to your batch file; right click; properties.

edit:

you can also set your current working directory using the start command:

start "Title" /D "C:\WeirdProgram\WeirdProgramModule\" "weirdmodule.exe"

edit:

If you like to pass params, just add them to the executable filename as you would in a regular shortcut:

start "Title" /D "C:\WeirdProgram\WeirdProgramModule\" "weirdmodule.exe" "param1 param2"

or

start "Title" /D "C:\WeirdProgram\WeirdProgramModule\" "weirdmodule.exe param1 param2"

For reference, the syntax is described here: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx?mfr=true.


What's happening is that weirdmodule.exe is looking in the "current directory" for the .mdb file. You might be able to tell it where to find the .mdb file through a command line parameter or some other configuration method (registry or .ini file maybe). How you'd specify the location is entirely up to the weirdmodule.exe program, though.

Other than that, your current workaround is probably what you're stuck with.

As far as your problem with using start.exe... the start.exe program has the very, very odd behavior (bizarre behavior in my opinion) of treating the first parameter as the 'title' to put in the window if (and only if) the first parameter is in quotes. So you have a couple of options:

  • Don't use quotes to specify the program. This works for you because you don't need quotes (there aren't any spaces or other special characters in the path that would require quoting it):

    start C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe
    
  • Give an empty (or some other string) title as the first parameter. This is something you'd have to do if your path required quotes:

    start "" "C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe"
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜