从另一个批处理文件运行一个批处理文件

发布于 2025-01-01 14:15:12 字数 1103 浏览 0 评论 0原文

我想从批处理文件 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 调用批处理文件 1 时,由于路径不同,因此无法执行 VS2008.sln。 我不想更改批处理文件 1。是否可以更改批处理文件 2 来执行批处理文件 1。

I want to run Batch file 1(Path C:\3rdparty\Test\App) from Batch file 2(C:)
and VS2008.sln is there in C:\3rdparty\Test\App\VS2008

Batch File 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."

Batch File 2

echo "Running Batch File 2"
call C:\3rdparty\Test\App\BatchFile1.bat

Here when batchfile1 is called from Batchfile2 it is not able to execute VS2008.sln since path is different.
I Don't want to change batchfile1.Is it possible to do changes in batch file 2 to execute the Batch file1.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海螺姑娘 2025-01-08 14:15:12

尝试将目录更改为 BatchFile1 的目录。

echo "Running Batch File 2" 
cd C:\3rdparty\Test\App
call BatchFile1.bat 

Try changing the directory to the directory of BatchFile1.

echo "Running Batch File 2" 
cd C:\3rdparty\Test\App
call BatchFile1.bat 
被翻牌 2025-01-08 14:15:12

我已在脚本中添加了一个本地变量,该变量设置为 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."

I've added a local variable to your script that is set to the BatchFile1 path, whatever it is, so now you can use path relative to the BatchFile1 path.

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."
演出会有结束 2025-01-08 14:15:12

您可以将

pushd %~dp0

popd

代码放在batchfile1.bat中,

会将当前目录更改为batchfile1所在的位置,然后在完成后更改回来

You could put

pushd %~dp0

and

popd

around your code in batchfile1.bat

which would change the current directory to wherever batchfile1 is and then change back when you've done

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文