File: util.py

package info (click to toggle)
ns3 3.7.1-7
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 186,596 kB
  • ctags: 507,963
  • sloc: ansic: 1,455,115; cpp: 151,502; python: 72,564; asm: 5,317; perl: 4,801; makefile: 1,107; sh: 1,023; tcl: 295; lex: 230
file content (24 lines) | stat: -rw-r--r-- 519 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import sys
import subprocess

def fatal(msg):
    print >> sys.stderr, msg
    sys.exit(2)

class CommandError(Exception):
    pass

def run_command(*args, **kwargs):
    if len(args):
        argv = args[0]
    elif 'args' in kwargs:
        argv = kwargs['args']
    else:
        argv = None
    if argv is not None:
        print " => ", ' '.join(argv)

    cmd = subprocess.Popen(*args, **kwargs)
    retval = cmd.wait()
    if retval:
        raise CommandError("Command %r exited with code %i" % (argv, retval))