我有一个要求,我需要运行一个批处理脚本,该脚本将编译自定义模块,然后返回到项目的根位置并运行该项目。
为此,我写了如下内容
SET curDir=%~dp0
PUSHD %curDir%
echo %curDir%
cd modules\custom-module
yarn build
POPD
echo %CD%
yarn start
但是在
yarn build
命令之后,它保留在 modules\custom-module
目录中。
在更改目录之前,请调用“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