Window Batch File: Calling an Executable File in Another Directory

This seems like something simple, but it seems like I can't get it. I have a directory called "test" with the executable hello.exe, which basically displays "hello" on the screen.

I want to run this program from the current directory using relative paths. Therefore i write

 test \ hello.exe

Thinking that he will run the program "hello.exe", located in the directory "test". But this is not so. Did I miss something?

+8
windows-vista batch-file
source share
1 answer

Try the following in a batch file:

%~dp0test\hello.exe 

"% ~ dp0" is a variable that is replaced with the full outline of the batch file, so it should work even if you do not set the current directory of the batch file.

+16
source share

All Articles