user3629892
user3629892

Reputation: 3046

calling batch file that calls yet another batch file fails

I have a batch file a.bat that effectively looks like this:

call some.bat

java -cp "saxon9he.jar" net.sf.saxon.Transform  abc.xml des.xsl > des.xml

call subfolder\other.bat

And the other.bat in subfolder effectively looks like this:

call yet_another_batch.bat

java -cp "../saxon9he.jar" net.sf.saxon.Transform any.xml try.xsl > try.xml
java -cp "../saxon9he.jar" net.sf.saxon.Transform ../some.xml test.xsl

So in the first file (a.bat), I call another batch file in the same folder and some xsl scripts in the same folder that write xml files into the same folder. From the first batch script (a.bat) I'd like to call the subfolder\other.bat. However, when I do that, it fails to call the yet_another_batch.bat in subfolder and also the xsl scripts in subfolder and it doesnt find the saxon9he.jar.

What's the correct way to do this? Do I have to add the folder name to all the files referenced in the subfolder\other.bat? Seems a little cumbersome. I'm on Windows 7, if that changes anything.

Upvotes: 1

Views: 102

Answers (1)

wimh
wimh

Reputation: 15232

Add two lines lines to other.bat like this:

pushd "%~dp0"
call yet_another_batch.bat

java -cp "../saxon9he.jar" net.sf.saxon.Transform any.xml try.xsl > try.xml
java -cp "../saxon9he.jar" net.sf.saxon.Transform ../some.xml test.xsl
popd

Using pushd, other.bat will execute it's commands from it's own folder. popd sets it back so the directory will not be changed when you return in a.bat

Upvotes: 2

Related Questions