diff options
| author | mryouse | 2022-05-13 23:22:05 +0000 |
|---|---|---|
| committer | mryouse | 2022-05-13 23:22:05 +0000 |
| commit | 9689c86239d78c085587b88064b3d43571e92475 (patch) | |
| tree | 9a3d022c44f7d36d3222c423ee2cc46acb57d171 /std.py | |
| parent | 47a483d875e9bd0fb0575f9450790eb962e0d799 (diff) | |
shell commands throw exception when they fail
Diffstat (limited to 'std.py')
| -rw-r--r-- | std.py | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -23,12 +23,13 @@ def std_print(arg): return NebNil() def std_print_all(arg): - for idx, item in enumerate(arg.items): + items = arg.items + for idx, item in enumerate(items): if isinstance(item, NebExpression): - arg.items[idx] = evaluate_expression(item) + items[idx] = evaluate_expression(item) elif not isinstance(item, NebString): raise exception("print-all needs all strings!") - for x in arg.items: + for x in items: std_print(x) return NebNil() @@ -153,9 +154,9 @@ def std_literal_to_string(arg): def std_shell(arg): assert isinstance(arg, NebString) lst = arg.value.split(" ") - ret = subprocess.run(lst, capture_output=True) + ret = subprocess.run(lst, capture_output=True, check=True) stdout_as_list = ret.stdout.decode("utf-8").split("\n")[:-1] - return NebList([ret.returncode] + stdout_as_list) + return NebList(list(NebString(x) for x in stdout_as_list)) def std_shell_pipe(args): prev = None @@ -166,20 +167,19 @@ def std_shell_pipe(args): lst = arg.value.split(" ") if prev is None: if stdout is None: - ret = subprocess.run(lst, capture_output=True) + ret = subprocess.run(lst, capture_output=True, check=True) else: - ret = subprocess.run(lst, stdout=stdout) + ret = subprocess.run(lst, stdout=stdout, check=True) else: if stdout is None: - ret = subprocess.run(lst, input=prev.stdout, capture_output=True) + ret = subprocess.run(lst, input=prev.stdout, capture_output=True, check=True) else: - ret = subprocess.run(lst, stdout=stdout, input=prev.stdout) + ret = subprocess.run(lst, stdout=stdout, input=prev.stdout, check=True) - # TODO should we bail here if the return code is non-zero? prev = ret stdout_as_list = prev.stdout.decode("utf-8").split("\n")[:-1] - return NebList([prev.returncode] + stdout_as_list) + return NebList(list(NebString(x) for x in stdout_as_list)) def evaluate_expression(expr): if not expr.symbol.name in STD: |
