Batch script stops executing after `gulp` process

2019-06-17 07:41发布

问题:

I am attempting to write a simple batch file to build a gulp project and a maven project.

The current file follows:

cd C:\my\file\path
cmd /k gulp maven-deploy-local
cd C:\my\file\path\two\project-pom-parent
cmd /k mvn clean install -Dmaven.test.skip=true

Whenever I run this script, the command line stops after line 2 and before line 3. I end up looking at this line in cmd with a blinking cursor:

C:\my\file\path>

If I run the file without the cmd /k (as follows) then the prompt simply closes after line 2 and before line 3.

cd C:\my\file\path
gulp maven-deploy-local
cd C:\my\file\path\two\project-pom-parent
mvn clean install -Dmaven.test.skip=true

How can I modify the batch script so that it will continue and execute the commands on lines 3 and 4 and then remain open with the following line and blinking cursor?

C:\my\file\path\two\project-pom-parent>

I am operating on Windows 7 64-bit

回答1:

This task is specific enough to use this as well:

cd /d "C:\my\file\path"
cmd /c gulp maven-deploy-local
cd /d "C:\my\file\path\two\project-pom-parent"
cmd /k mvn clean install -Dmaven.test.skip=true

In essence the first cmd /k can be changed to cmd /c so it executes the command and continues to the last command, which leaves the prompt open.



回答2:

@ECHO OFF
IF NOT "%1"=="1" CMD /K ""%~f0" 1"
CD /d C:\my\file\path
CALL gulp maven-deploy-local
CD /d C:\my\file\path\two\project-pom-parent
CALL mvn clean install -Dmaven.test.skip=true