2015-06-13 293 views
1

我有一個批處理文件a.bat,有效地看起來像這樣:調用另一個批處理文件調用批處理文件失敗

call some.bat 

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

call subfolder\other.bat 

而且在subfolderother.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 

所以在第一個文件(a.bat)中,我調用同一文件夾中的另一個批處理文件以及將xml文件寫入同一文件夾的同一文件夾中的一些xsl腳本。 從第一批腳本(a.bat)開始,我想致電subfolder\other.bat。但是,當我這樣做時,它不能在subfolder中調用yet_another_batch.bat,也不能在subfolder中調用xsl腳本,並且找不到saxon9he.jar。

這樣做的正確方法是什麼?是否必須將文件夾名稱添加到subfolder\other.bat中引用的所有文件?似乎有點麻煩。我在Windows 7上,如果這改變了任何東西。

回答

2

添加兩條線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 

使用pushd,other.bat將執行它從它自己的文件夾命令。 popd將它設置回來,以便在返回時不會更改目錄a.bat

+0

非常感謝,作品像魅力:) – user3629892

相關問題