[英]Windows batch file changes the location for the second command
I want to create a batch file to execute my Angular project:我想创建一个批处理文件来执行我的 Angular 项目:
setlocal
cd /d %~dp0
cd ui
npm i && npm start
The file simply goes to the current directory, and then goes to ui
folder.该文件只是转到当前目录,然后转到
ui
文件夹。 First runs a npm i
command, and then runs nmp start
command.首先运行
npm i
命令,然后运行 nmp nmp start
命令。 The problem is the second commands gives me the following error:问题是第二个命令给了我以下错误:
npm ERR: path C.\Windows\System32\package.json
npm ERR:路径 C.\Windows\System32\package.json
......
Surprisingly the locations is changed to C:\Windows\System32\
and npm start
command can not find a package.json
file there. Surprisingly the locations is changed to
C:\Windows\System32\
and npm start
command can not find a package.json
file there. I want to know why does it happen and how I can prevent it.我想知道为什么会发生这种情况以及如何预防。 I want the second command to be executed at the same directory.
我希望在同一目录中执行第二个命令。
As @Compo suggested, adding a call at the beginning of the last line solved the problem.正如@Compo 建议的那样,在最后一行的开头添加一个调用解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.