File: util.py

package info (click to toggle)
ns3 3.30+dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 128,572 kB
  • sloc: cpp: 502,306; python: 399,018; perl: 8,720; ansic: 7,158; xml: 3,918; makefile: 2,073; sh: 771
file content (25 lines) | stat: -rw-r--r-- 561 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from __future__ import print_function
import sys
import subprocess

def fatal(msg):
    print(msg, file=sys.stderr)
    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))