views:

224

answers:

2

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 the 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,

+3  A: 

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"
    
Michael Burr
The `mdb` file is right next to the `exe` file. I would think that it would look in the same path that it was called from before looking in the path that called it (if that makes any sense).
Anthony
The current directory will likely be the location of the batch file you are running. That is why your solution works (the current directory has changed to the exe).
Russell
@Anthony: you're right that looking in the application directory often makes sense. It's a common technique - though I think that usually the current directory is looked in first, then the application directory. That gives users a bit more flexibility if they want to have multiple data sets. Unfortunately, you're at the mercy of whoever coded up the program to give it the flexibility it should have.
Michael Burr
+3  A: 

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"
henchman
You get the answer bonus for showing me how to execute in one line. It's all the same, from what you both are saying, but my superiors were wanting something tight as a drum.
Anthony