Section 6.12. Exit Status


6.12. Exit Status

You may at some point want to write a script that includes one or more CVS commands, such as a script to automatically export files from a repository to a web server, or a script to automatically update a test directory and attempt to build a program. If you do, you will need to know whether a given CVS command succeeded.

CVS commands set an exit status when they complete processing. A successful command always returns the success status. A failing command prints an error message and returns the failure status.

The cvs diff command behaves differently from the other commands. It returns success if it finds no differences and failure if it finds differences or encounters an error. This behavior may change in later versions of CVS.

Testing the exit status depends on the operating system. In Unix and Linux, the sh shell variable $? is 0 if CVS returns success, and nonzero if it returns a failure. Example 6-19 shows a script to test a CVS return value, and Example 6-20 shows a Windows version of the same script.

Example 6-19. Testing return values in bash

 cvs commit -m "Automated commit" if [ $? -eq 0 ]; then         echo "Commit successful." else         echo "Commit failed with return code $?" fi 

Example 6-20. Testing return values in Windows

 @echo off cvs commit -m "Automated commit" if %ERRORLEVEL% GEQ 1 goto ERR goto OKAY :ERR   echo "Commit failed with return code %ERRORLEVEL%"   goto END :OKAY   echo "Commit successful." :END 




Essential CVS
Essential CVS (Essentials)
ISBN: 0596527039
EAN: 2147483647
Year: 2006
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net