Issue Environment : Windows Server 2008 R2 Build 7601
I have a batch file SomeBatchFile.bat
which uses %~dp0
to get the script location. But when it's executed on Windows Server 2008 R2 Build 7601
from a java program, its showing a buggy behavior.
Here is the behavior,
1) When executed like this
Process proc= Runtime.getRuntime().exec("c:\\full\\path\\SomeBatchFile.bat");
Keeping the SomeBatchFile.bat
file in C:\full\path
(essentially giving the actual full path), its returning the expected result c:\full\path\
2) But when executed like this
Process proc= Runtime.getRuntime().exec("SomeBatchFile.bat");
Keeping the SomeBatchFile.bat
file in C:\Windows
(essentially a location that is a part of environment variable PATH
).This returns a wrong value instead of the BAT script location
, its returning the java program location
from where this script is called.
This is the script file I am using,
REM Just prints the script location to a file
set MY_HOME=%~dp0
echo %MY_HOME% >> test_out.txt
REM And some other business logic here ...
On Windows Server 2003, this is working absolutely fine.
Any idea why this happens like this ? Is this Java/Windows Bug ? And how to resolve this ?