我想从批处理文件2(C :)运行批处理文件1(路径C:\ 3rdparty \ Test \ App) 和VS2008.sln在C:\ 3rdparty \ Test \ App \ VS2008
中批处理文件1
REM BatchFile1.bat
set DEVENV_PATH=%VS90COMNTOOLS%..\IDE
REM ---------------------------------------------------------------------
set OUTDIR=.\output\windows\x86
rmdir /S /Q %OUTDIR%
mkdir %OUTDIR%
call "%DEVENV_PATH%\devenv.com" VS2008\VS2008.sln /Rebuild "Release|Win32"
call "%DEVENV_PATH%\devenv.com" VS2008\VS2008.sln /Rebuild "Debug|Win32"
REM ---------------------------------------------------------------------
set OUTDIR=.\output\windows\x64
rmdir /S /Q %OUTDIR%
mkdir %OUTDIR%
call "%DEVENV_PATH%\devenv.com" VS2008\VS2008.sln /Rebuild "Release|x64"
call "%DEVENV_PATH%\devenv.com" VS2008\VS2008.sln /Rebuild "Debug|x64"
REM ---------------------------------------------------------------------
echo "BatchFile1.bat completed."
批处理文件2
echo "Running Batch File 2"
call C:\3rdparty\Test\App\BatchFile1.bat
这里,当从Batchfile2调用batchfile1时,由于路径不同,因此无法执行VS2008.sln。 我不想更改batchfile1.是否可以在批处理文件2中进行更改以执行批处理文件1.
答案 0 :(得分:4)
尝试将目录更改为BatchFile1目录。
echo "Running Batch File 2"
cd C:\3rdparty\Test\App
call BatchFile1.bat
答案 1 :(得分:1)
我在脚本中添加了一个设置为BatchFile1路径的局部变量,无论它是什么,所以现在可以使用相对于BatchFile1路径的路径。
REM BatchFile1.bat
set scriptPath=%~dp0
set scriptPath=%scriptPath:~0,-1%
rem now %scriptPath% contain the script path, and then you can use command like
rem "%scriptPath%\MyCommand.exe" /MyParameter=123_abcd
set DEVENV_PATH=%VS90COMNTOOLS%..\IDE
REM ---------------------------------------------------------------------
set OUTDIR=.\output\windows\x86
rmdir /S /Q %OUTDIR%
mkdir %OUTDIR%
call "%DEVENV_PATH%\devenv.com" "%scriptPath%\VS2008\VS2008.sln" /Rebuild "Release|Win32"
call "%DEVENV_PATH%\devenv.com" "%scriptPath%\VS2008\VS2008.sln" /Rebuild "Debug|Win32"
REM ---------------------------------------------------------------------
set OUTDIR=.\output\windows\x64
rmdir /S /Q %OUTDIR%
mkdir %OUTDIR%
call "%DEVENV_PATH%\devenv.com" "%scriptPath%\VS2008\VS2008.sln" /Rebuild "Release|x64"
call "%DEVENV_PATH%\devenv.com" "%scriptPath%\VS2008\VS2008.sln" /Rebuild "Debug|x64"
REM ---------------------------------------------------------------------
echo "BatchFile1.bat completed."
答案 2 :(得分:0)
你可以把
pushd %~dp0
和
popd
在batchfile1.bat
中的代码周围会将当前目录更改为batchfile1所在的位置,然后在完成后再更改