checked_system.py 576 B

12345678910111213141516171819202122
  1. import os
  2. import string
  3. import sys
  4. def system( commands ):
  5. if sys.platform == 'win32':
  6. f = open( 'tmp.cmd', 'w' )
  7. f.write( string.join( commands, '\n' ) )
  8. f.close()
  9. rc = os.system( 'tmp.cmd' )
  10. return rc
  11. else:
  12. rc = os.system( '&&'.join( commands ) )
  13. return rc
  14. def checked_system( commands, valid_return_codes = [ 0 ] ):
  15. rc = system( commands )
  16. if rc not in [ 0 ] + valid_return_codes:
  17. raise Exception( 'Command sequence "%s" failed with return code %d' % ( commands, rc ) )
  18. return rc
粤ICP备19079148号