Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
939 views
in Technique[技术] by (71.8m points)

creating a .bat file with npm install command

I created the following file

//npminstall.bat

npm install
echo hello

When I run the following command from Windows 10 Command Line (dos) npminstall.bat, the npm install command fires, but the echo hello doesn't fire. I tried putting a semi-color after the first line like this npm install;, but all that did was give me the help instructions of npm .

How do I get the second line echo hello to fire after the npm install?

Additional Notes

I have found that this also causes the same behaviour:

//npminstall.bat

webpack
echo hello

I think it's because both the npm install command and webpack command takes time to execute, and during that time it doe ssomething I don't expect to the second line.

Followup 2

//npminstall.bat

START /WAIT npm install
echo hello

This seems to almost do what I want to do. Except the npm install command causes a pop up window, and i have to shut down teh pop up window before it continues execution to echo hello world. Can I get rid of the popup window?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When you access another batch file from a batch file, you need to use the CALL command to return control to parent process otherwise control is passed to the batch file being executed.

call npm install

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...