comparison python/logoutput.py @ 511:d7afa7a0ea3e

new
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 06 Sep 2013 17:11:33 -0700
parents
children
comparison
equal deleted inserted replaced
510:44f9b67bb56f 511:d7afa7a0ea3e
1 #!/usr/bin/env python
2
3 """
4 execute a command and log its output to a file
5 """
6
7 import sys
8 from subprocess import list2cmdline, STDOUT
9 from subprocess import check_output as call
10
11 def main(args=sys.argv[1:]):
12 """CLI"""
13
14 usage = '%prog outputfile command [args]'
15 usage += '\n' + __doc__
16 if args < 2:
17 print 'Usage: ' + usage
18 sys.exit(1)
19
20 path = args.pop(0)
21 commandline = list2cmdline(args)
22
23 with file(path, 'w') as w:
24 output = call(args, stderr=STDOUT)
25 w.write('\n\n'.join([commandline, output]))
26
27 if __name__ == '__main__':
28 main()