views:

52

answers:

2

I have in the same folder a .bat and a .exe file. I couldn't call the .exe file from the .bat unless I put the full absolute path to it. Is there a way to don't specify the path?

A: 

seems odd? I haven't worked on windows for sometime but

did you try leading with a ./

./program.exe

really should be no difference? maybe the bat is executing from the context of C:\Windows or did your batch do any cd to another dir at some point?

house9
You meant .\ (that is, backslash).
Philip Kelley
I think that when I execute the batch it is being executed from another directory.
Jader Dias
Maybe my question is "how to double click a batch file and make it execute in the same directory as it is?"
Jader Dias
doh! yes you are right a backslash
house9
. is the current directory aka working directory and could be changed in a batch with cd and pushd.
Anders
+2  A: 

Try calling the .exe with %~dp0, like this: %~dp0MyProgram.exe.

%0 contains the full path to the called .bat file.

~dp says to get the drive and path, including trailing \.

Patrick Cuff
+1 votejust found this link on google search - http://weblogs.asp.net/whaggard/archive/2005/01/28/get-directory-path-of-an-executing-batch-file.aspx
house9