Windows批处理脚本中PUSH和POPD的使用

问题描述 投票:0回答:1

我有一个要求,我需要运行一个批处理脚本,该脚本将编译自定义模块,然后返回到项目的根位置并运行该项目。

为此,我写了如下内容

SET curDir=%~dp0
PUSHD %curDir%
echo %curDir%
cd modules\custom-module
yarn build
POPD
echo %CD%
yarn start

但是在

yarn build
命令之后,它保留在
modules\custom-module
目录中。

windows batch-file
1个回答
0
投票

在更改目录之前,请调用“setlocal”。所以你的脚本将如下所示

cd                            <- prints current dir
setlocal
cd modules\custom-module
yarn build                    <- if yarn is script, do 'call yarn build' instead
endlocal
cd
yarn start
© www.soinside.com 2019 - 2024. All rights reserved.