File: util.py

package info (click to toggle)
ns3 3.17%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 95,192 kB
  • ctags: 56,763
  • sloc: cpp: 324,361; python: 291,824; perl: 8,720; ansic: 2,097; xml: 2,000; makefile: 1,447; sh: 458; cs: 89
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))