MCPcopy Create free account
hub / github.com/AMReX-Codes/amrex / run

Function run

Tools/F_scripts/preprocess.py:6–29  ·  view source on GitHub ↗

run a command in the unix shell

(command, stdin=False, outfile=None)

Source from the content-addressed store, hash-verified

4import sys
5
6def run(command, stdin=False, outfile=None):
7 """ run a command in the unix shell """
8
9 sin = None
10 if stdin: sin = subprocess.PIPE
11 p0 = subprocess.Popen(command, stdin=sin, stdout=subprocess.PIPE,
12 stderr=subprocess.STDOUT, shell=True)
13
14 stdout0 = p0.communicate()
15 if stdin: p0.stdin.close()
16 rc = p0.returncode
17 p0.stdout.close()
18
19 if outfile is not None:
20 try: cf = io.open(outfile, "w", encoding="latin-1")
21 except IOError:
22 sys.exit("ERROR: unable to open file for writing: {}".format(outfile))
23 else:
24 for line in stdout0:
25 if line is not None:
26 cf.write(line.decode('latin-1'))
27 cf.close()
28
29 return stdout0, rc
30
31
32class Preprocessor(object):

Callers 1

preprocessMethod · 0.70

Calls 3

communicateMethod · 0.80
formatMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected