Changes in tests/pybin/tools.py [f58522b0:0fc91db1]
- File:
-
- 1 edited
-
tests/pybin/tools.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/pybin/tools.py
rf58522b0 r0fc91db1 23 23 24 24 # helper functions to run terminal commands 25 def sh(*cmd, timeout = False, output_file = None, input_file = None, input_text = None, error = subprocess.STDOUT, ignore_dry_run = False, pass_fds = [] , nice = False):25 def sh(*cmd, timeout = False, output_file = None, input_file = None, input_text = None, error = subprocess.STDOUT, ignore_dry_run = False, pass_fds = []): 26 26 try: 27 27 cmd = list(cmd) … … 58 58 error = openfd(error, 'w', onexit, False) 59 59 60 # prepare the parameters to the call61 popen_kwargs = {62 'stdout' : output_file,63 'stderr' : error,64 'pass_fds': pass_fds,65 }66 67 # depending on how we are passing inputs we need to set a different argument to popen68 if input_text:69 popen_kwargs['input'] = bytes(input_text, encoding='utf-8')70 else:71 popen_kwargs['stdin'] = input_file72 73 # we might want to nice this so it's not to obnixious to users74 if nice:75 popen_kwargs['preexec_fn'] = lambda: os.nice(5)76 77 60 # run the desired command 78 61 # use with statement to make sure proc is cleaned 79 62 # don't use subprocess.run because we want to send SIGABRT on exit 80 with subprocess.Popen( cmd, **popen_kwargs ) as proc: 63 with subprocess.Popen( 64 cmd, 65 **({'input' : bytes(input_text, encoding='utf-8')} if input_text else {'stdin' : input_file}), 66 stdout = output_file, 67 stderr = error, 68 pass_fds = pass_fds 69 ) as proc: 70 81 71 try: 82 72 out, errout = proc.communicate(
Note:
See TracChangeset
for help on using the changeset viewer.