views:

510

answers:

5

I created a simple batch file (.bat) containing a bunch of commands to be triggered automatically into the command window. The batch looks like this:

mmd dll1.dll -mf -aW
mmd dll2.dll -mf -aW
mmd dll3.dll -mf -aW

If I copy and paste the bunch of cmds into the command window, they are all correctly executed. However, if I try to directly drag the batch file into the command window and execute it, the first command starts and ends up failing to succesfully execute. Why?

The command window where I run the commands needs to set a lot of environment variables before the commands can succesfully run. When I drag the batch file (with absolute path) it looks like I never set those variables. Don't the commands from the batch file run in the same context with the hosting command window? How do I do that then?

A: 

Are you putting quotes around the file names you are calling? And are the file names on different lines? (If not, they should be)

George Stocker
+1  A: 

It is executing the dragged in file with a path relative to the .bat file (and not where those dlls actually are)?

Michael Haren
A: 

Has your PATH been set correctly? Are you in the correct directory when you execute the batch? Have you checked for invisible, invalid characters in the batch file?

Vincent Van Den Berghe
+1  A: 

It's possible the you've got special characters in your commands that affect batch files, such as %. You'll need to escape/remove these.

Otherwise, it's probably something to do with the program you're running either messing with the terminal or being very dependent on its environment. Do you have any information on it? Try running just the first line in a batch file.

Mark
Actually the command is depending on the context of the command window. In order for the commands to work, the hosting command window needs to set a lot of environment variables. Isn't that context inherited if I drag the batch file in the cmd window? How to I do that then?
Daniel Stanca
+1  A: 

do you try to add "call" before the commands in the ".bat" ?

By adding "call" before your cmd line you guarantee that the father-proccess continues working when the child-proccess ends.

damian
This only applies if mmd is mmd.bat or mmd.cmd. It doesn't actually work with processes.
Mark