MCPcopy Create free account
hub / github.com/NetSys/bess / cmd

Function cmd

build.py:46–82  ·  view source on GitHub ↗

Run a command. If quiet is True, or if V is not set in the environment, eat its stdout and stderr by default (we'll print both to stderr on any failure though). If V is set and we're not forced to be quiet, just let stdout and stderr flow through as usual. The name V is from

(cmd, quiet=False, shell=False)

Source from the content-addressed store, hash-verified

44
45
46def cmd(cmd, quiet=False, shell=False):
47 """
48 Run a command. If quiet is True, or if V is not set in the
49 environment, eat its stdout and stderr by default (we'll print
50 both to stderr on any failure though).
51
52 If V is set and we're not forced to be quiet, just let stdout
53 and stderr flow through as usual. The name V is from the
54 standard Linux kernel build ("V=1 make" => print everything).
55
56 (We use quiet=True for build environment test cleanup steps;
57 the tests themselves use use cmd_success() to check for failures.)
58 """
59 if not quiet:
60 quiet = os.getenv('V') is None
61
62 kwargs = {'universal_newlines': True}
63 if quiet:
64 kwargs['stdout'] = subprocess.PIPE
65 kwargs['stderr'] = subprocess.STDOUT
66 if shell:
67 proc = subprocess.Popen(cmd, shell=True, **kwargs)
68 else:
69 proc = subprocess.Popen(shlex.split(cmd), **kwargs)
70
71 # There is never any stderr output here - either it went straight
72 # to os.STDERR_FILENO, or it went to the pipe for stdout.
73 out, _ = proc.communicate()
74
75 if proc.returncode:
76 # We only have output if we ran in quiet mode.
77 if quiet:
78 print('Log:\n', out, file=sys.stderr)
79 print('Error has occured running command: %s' % cmd, file=sys.stderr)
80 sys.exit(proc.returncode)
81
82 return out
83
84
85BESS_DIR = os.path.dirname(os.path.abspath(__file__))

Callers 12

build.pyFile · 0.70
check_headerFunction · 0.70
check_c_libFunction · 0.70
download_dpdkFunction · 0.70
configure_dpdkFunction · 0.70
build_dpdkFunction · 0.70
generate_protobuf_filesFunction · 0.70
gen_one_set_of_filesFunction · 0.70
build_bessFunction · 0.70
build_kmodFunction · 0.70
do_cleanFunction · 0.70
do_dist_cleanFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected