comparison common/misc.py @ 359:9e73e6dc9823

Improved runcmd
author Joseph Turian <turian@iro.umontreal.ca>
date Wed, 02 Jul 2008 15:42:42 -0400
parents faece52be094
children 0e3af3c53ac7
comparison
equal deleted inserted replaced
358:faece52be094 359:9e73e6dc9823
1 def runcmd(cmd): 1 def runcmd(args):
2 """ 2 """
3 Run a command and return its output 3 Split args into a list, run this command, and return its output.
4 Raise RuntimeError if the command does not return 0.
4 """ 5 """
5 import popen2 6 import subprocess
6 (pin, pout) = popen2.popen2(cmd) 7 print args
7 return pin.read() 8 import string
9 proc = subprocess.Popen(string.split(args), stdout=subprocess.PIPE)
10 output = proc.communicate()[0]
11 if proc.returncode != 0:
12 import exceptions
13 raise exceptions.RuntimeError
14 return output
8 15
9 def sign(i, assertions=True): 16 def sign(i, assertions=True):
10 """ 17 """
11 + or - 1 18 + or - 1
12 @precondition: i != 0 19 @precondition: i != 0