[英]calling batch file that calls yet another batch file fails
I have a batch file a.bat
that effectively looks like this: 我有一个批处理文件
a.bat
,它实际上看起来像这样:
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: subfolder
的other.bat
实际上看起来像这样:
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. 因此,在第一个文件(
a.bat
)中,我在同一文件夹中调用另一个批处理文件,并在同一文件夹中调用一些xsl脚本,这些脚本将xml文件写入同一文件夹。 From the first batch script ( a.bat
) I'd like to call the subfolder\\other.bat
. 在第一个批处理脚本(
a.bat
)中,我想调用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. 然而,当我做到这一点,它不能称之为
yet_another_batch.bat
在subfolder
,并在XSL脚本subfolder
和它没有找到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
? 我是否必须将文件夹名称添加到
subfolder\\other.bat
引用的所有文件中? Seems a little cumbersome. 似乎有点麻烦。 I'm on Windows 7, if that changes anything.
我在Windows 7上,如果一切有变。
Add two lines lines to other.bat like this: 将两行代码添加到other.bat中,如下所示:
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. 使用
pushd
,other.bat将在其自己的文件夹中执行命令。 popd
sets it back so the directory will not be changed when you return in a.bat
popd
将其设置回原来的位置,因此当您返回a.bat
时目录不会更改
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.