Reputation: 313
I have some Java code which executes a certain command on a Windows machine. However, it's behaviour is bizarre in that the same command works on one machine, but fails on three others. As far as I can tell each of the four machines are identical.
The command is this:
cmd /c %APP_HOME%\..\..\some\more\path\executable -arg1=value1 -arg2=value2 -errorlogname=%APP_HOME%\logs\errors.log -arg3 some more parameters
Where %APP_HOME%
is a system variable set to the value "D:/path/to/program".
The error I get is this:
Application specific error message about not being able to open one of the logs or "a related file": d:/path/to/program\logs. errno = 13, Permission denied
The Java I'm using looks like this:
Runtime.getRuntime().exec(cmdStr);
Where cmdStr
is a String containing the command as described above. Now, things that I know are;
These are valid comments which I'll probably end up fixing the problem with, but what I'm trying to work out is why the exact same code fails on only 3 out of 4 machines.
And yes, all the paths on mentioned in the command exist on the box.
And it gets more strange. If I execute the following (very similar) command it works fine on all four boxes.
cmd /c %APP_HOME%\..\..\some\more\path\executable -arg1=value1 -arg2=value2 -errorlogname=D:\path\to\program\logs\errors.log -arg3 some more parameters
In the above working version, the only difference is the %APP_HOME%
reference has been replaced with the absolute path for the -errorlogname
argument. But the variable has been left to point at location of the executable.
Now the fact that the identical code runs fine on one box leads me suspect that the problem is not the Java code. Similarly, the mix of slash directions I don't see being a problem, because this concoction works on one machine.
In my view, it should be failing on every machine. Not just one of them.
Obviously, if everything really was identical it would break (or work) on every machine. But all the things I've thought to look at are identical.
Can anyone else suggest anything else to consider?
Many thanks.
Upvotes: 1
Views: 404
Reputation: 86754
I suspect %APP_HOME%
is actually not set on the failing machine, but you happen to be launching the script in the correct directory for the relative path to the executable to work. To debug this further you're going to have to actually verify that %APP_HOME%
has the right value by printing it out.
Upvotes: 2