noob question about running programs from other directories

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
baixiwei
Posts: 2
Joined: 14 Mar 2012 10:13

noob question about running programs from other directories

#1 Post by baixiwei » 14 Mar 2012 10:19

Rather new to running batch files from command line so this is probably a really easy question, but I couldn't find the answer after some searching, so ...

I want my batch file to run a file in another directory with some parameters, like this:

directory\script.sh -param val -param val

It works OK when I put the batch file in the same directory (so I don't need the "directory\" part above), but it doesn't work when I'm running it from a different directory. In this case the command looks like

"long directory path with some spaces\script.sh" -param val -param val

And the problem is that the parameters don't seem to be getting properly passed to the script. In other words, I get the same error as I get if I run the script from its own directory without parameters. Any idea how I can fix this? Thanks in advance!

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: noob question about running programs from other director

#2 Post by aGerman » 14 Mar 2012 11:45

Hmm, should work. Does the content of "val" relate to the path where the script is placed? Note that the working directory stays the folder where the Batch file is placed.
Try changing the working directory:

Code: Select all

pushd "long directory path with some spaces"
script.sh -param val -param val
popd

Regards
aGerman

baixiwei
Posts: 2
Joined: 14 Mar 2012 10:13

Re: noob question about running programs from other director

#3 Post by baixiwei » 14 Mar 2012 12:08

This fix worked fine. Thanks!

By the way, no, the value of val didn't relate to the path where the script was placed.

Post Reply