17
votes

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.

5
you're searching in the wrong direction: if phpunit crashes the batch will continueCharlesB
do phploc and phing execute if you comment out phpunit call?CharlesB
This is more of a Super User thing...fretje
You should try to understand why it crashes instead of changing call. Dirty fixes always bite you (or your successor) later.CharlesB
@CharlesB Hey bud you were right, the phploc script was choking without outputing anything and I thought it was running fine. What is wrong with using call though, if you need a script to keep going regardless of failures? Is there a way to cactch return status of the script? I will peek into this tomorrow out of curiosity, I will maybe not touch windows again for a long while once this is up and working. Thanks for your input, +1'ed your comments for taking the time to clue me in! ;)stefgosselin

5 Answers

17
votes

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.

15
votes

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".

7
votes

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
2
votes

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

2
votes

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.