phpunit - Batch - How do I read the output of another command line function in a script? -


I am quite new to batch scripting, however, I have done a little bit scripting earlier. My batch file will be running another program (i.e. phpunit) and this program will output some stuff at the command prompt. How can I go about receiving a batch script, which prevents this stuff from the output and decides on the basis of it. For example, phpunit is usually a '.' For each test that runs successfully and 'F' for every exam that fails. How do I get a batch script to capture this output and I'll do something different depending on whether it's a ' Or an 'F'?

I will start by not answering your actual question, but whatever the underlying problem Trying to solve:

  1. You can do this in a way that machine is easy to read. PHP is a valid choice for writing commandline scripts. I use Bash for simple stuff for Bash, but once it's beyond some lines, or when I want to add a loop, If the statement, etc. I decide to do it properly in PHP. Other people can reach for pearl or dragon.

    In your special case I can not do it in PHP, because it can eliminate the need for some complex parsing but lets see how to do something simple in Bash. The challenge is that the output may look like this:

      PHPUnit 3.4.5 ..................... by Sebastian Bergman ................. Time: 10 seconds, Memory: 9.00 MB OK (38 tests, 660 assertions)   

    or may appear like this Is:

      PHPUnit 3.4.5 Sebastian Bergman. .................................................. .......... 60/380 ..................................... ....................... 120/380 ........................ ....................... S ............ 180/380 ....... S ... ................................................. 240 / 380 ............................................ .... ........ 300/380 ................................... .... ..................... 360/380 .................. Time: 01:44, Memory: 14.50 MB OK, but incomplete or omitted tests! Test: 380, convulsions: 6546, omitted: 2.   

    or it may look like this:

      PHPUnit 3.4.5 by SIBSTIAN Bergman .IIF Time: 0 seconds, Memory: 8.00 MB 1 was a failure: 1) Maitest :: Test Tiemz failed to ensure that & lt; Boolean: false & gt; It is true / Path / to / my test. Php: 68 Failures! Test: 4, Ascension: 5, Failures: 1, Incomplete: 1.   

    I'm guessing that your application will run all the tests and make sure that something like hourly cron If nothing has been broken, then I'm just going to hunt the word "failures":

      #! / Bin / bash RESULT = 'phpunit tests / myTest.php` if [[$ RESULT = "Failures]] Then the echo" I'm sorry, sir, but there is a problem in the unit tests ... "Capture" Output " "$ RESULT"   

    Some BASH experts will ask you to use $ () instead of any way here to do Works:

      .... RESULT = $ (phpunit test / myTest.php) ...    

Comments