Reputation: 9148
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.
Upvotes: 23
Views: 34449
Reputation: 1580
Found this while searching for a similar problem with automating clasp. Simple script
cd main
clasp pull
echo after pull
cd ..
doesn't echo and return back to original folder, while this solution does work
cd main
cmd /c clasp pull
echo after pull
cd ..
The reason here is simple: in Windows, if you run batch file from inside a batch file, the execution continues in child batch, but is NOT RETURNED BACK to parent back file.
The tricky thing here is it's very implicit that clasp (in my case) and phpunit - in original question, is also a batch file. That's why adding cmd /c solved the problem.
Posting this answer for other not-so-windows users like me who might encounter this behavior.
Upvotes: -1
Reputation: 1996
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.
Upvotes: 3
Reputation: 1389
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.
Upvotes: 25
Reputation: 12624
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".
Upvotes: 16
Reputation: 2245
Try start /WAIT phpunit ...
to fork process and wait for it or just start phpunit ...
to fork and continue. Help is here: start /?
Upvotes: 2
Reputation: 6229
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
Upvotes: 8