Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have .bat file continue after it runs a command

Tags:

batch-file

I need to figure out this seemingly very simple issue on windows .bat file. I have been using Linux for past 10 years full-time, so I am in pretty unfamiliar territory when it comes to .bat scripts.

We have some units tests that need to run on from this .bat file, and a build needs to be generated after the tests have run.

The bat file itself is very simple, I was thinking of just chaining the commands:

cls
echo "Running test suite - CRMSync"
echo 
echo 
REM from command: --static-backup
phpunit --bootstrap test/bootstrap_test.php --verbose --log-junit              
echo "Running  phploc for CRMSync"
phploc --count-tests --verbose > C:\CRMsync\testResults\phploc\index.html
echo "Executing phing"
phing

Now, simple enough except nothing is executed past phpunit command. How do I deal with this? The unit tests run fine, but I am suspecting it could even be in the unit test lib that process is killed. Is there a way to fork the process somehow or get the other commands below to run?

Thanks SO'ers, as always, any help greatly appreciated.

like image 582
stefgosselin Avatar asked Jun 15 '11 07:06

stefgosselin


5 Answers

I had the same problem for a development script that I made. And I tried all given solutions without being successful. At the end, I did it with cmd /C.

From the windows docs it will:

Run Command and then terminate

So for example, you can use it as follows:

cls
echo "Running test suite - CRMSync"
echo 
echo 
REM from command: --static-backup
cmd /C phpunit --bootstrap test/bootstrap_test.php --verbose --log-junit              
echo "Running  phploc for CRMSync"
cmd /C phploc --count-tests --verbose > C:\CRMsync\testResults\phploc\index.html
echo "Executing phing"
cmd /C phing

I hope you find this useful.

like image 91
Pedro José Piquero Plaza Avatar answered Oct 23 '22 23:10

Pedro José Piquero Plaza


Similar to the post ujifgc, I use "start /b ..." in these situations. If you encapsulate the call to phpunit in another batch file, you can use "call".

like image 42
Jahmic Avatar answered Oct 23 '22 23:10

Jahmic


Is phpunit itself a batch file (I don't do much PHP, so am not familiar with the tool)? If so, try using:

call phpunit --bootstrap test/bootstrap_test.php --verbose --log-junit
like image 7
developmentalinsanity Avatar answered Oct 23 '22 21:10

developmentalinsanity


Try start /WAIT phpunit ... to fork process and wait for it or just start phpunit ... to fork and continue. Help is here: start /?

like image 2
ujifgc Avatar answered Oct 23 '22 22:10

ujifgc


I used

start /b code .

cmd /k ng serve --build-optimizer --aot

to start Visual Studio Code and then a node js server.

But the Command line glitched with the % update text and more.

I then used

cmd /C code .

cmd /k ng serve --build-optimizer --aot

and the glitching stopped for the server progress update.

like image 2
Timar Ivo Batis Avatar answered Oct 23 '22 22:10

Timar Ivo Batis