简体   繁体   English

Windows 批处理文件更改第二条命令的位置

[英]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.

相关问题 'tsc' 不是内部或外部命令,也不是可运行的程序或批处理文件。 - Windows 7的 - 'tsc' is not recognized as an internal or external command, operable program or batch file. - Windows 7 'npm' 'node' 不是用于 Windows 的内部或外部命令,也不是可运行的程序或批处理文件 - 'npm' 'node' is not recognized as internal or external command, operable program or batch file for Windows 'eval' 在 windows npm 脚本上未被识别为内部或外部命令、可运行程序或批处理文件 - 'eval' is not recognized as an internal or external command, operable program or batch file on windows npm script 'install-peerdeps' 不是内部或外部命令,也不是可运行的程序或批处理文件 (windows 7) - 'install-peerdeps' is not recognized as an internal or external command, operable program or batch file (windows 7) 在 Windows 上运行forever.js 时出错-“'C:\\Program' 不是内部或外部命令、可运行的程序或批处理文件” - Error running forever.js on Windows - "'C:\Program' is not recognized as an internal or external command, operable program or batch file" 如何使用Node JS运行Windows批处理文件 - How to run a windows batch file with node js 避免在Windows批处理文件中的for循环中打印 - Avoid printing in a for loop on windows batch file 从Windows批处理文件返回字符串 - Return a String from a Windows Batch file 相对于文件位置运行脚本,而不是节点中的命令行位置 - Run script relative to file location, not command line location in node 卷曲命令未处理我对文件所做的更改 - Curl command is not processing changes I make to file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM