diff options
| author | mryouse | 2022-05-13 04:42:09 +0000 |
|---|---|---|
| committer | mryouse | 2022-05-13 04:42:09 +0000 |
| commit | c85ac13b0af00b0ad3c475e7044b413d82959ad5 (patch) | |
| tree | 662409c272e56aa46dd79f389de5b4e632fab624 | |
| parent | 5f019f545a7214c0c7c6cc8d789886ebfcb93eba (diff) | |
update shell commands to return list
| -rw-r--r-- | std.py | 28 |
1 files changed, 21 insertions, 7 deletions
@@ -125,8 +125,9 @@ def std_literal_to_string(arg): def std_shell(arg): assert isinstance(arg, NebString) lst = arg.value.split(" ") - subprocess.run(lst) - return NebBool(True) + ret = subprocess.run(lst, capture_output=True) + stdout_as_list = ret.stdout.decode("utf-8").split("\n")[:-1] + return NebList([ret.returncode] + stdout_as_list) def std_shell_pipe(args): prev = None @@ -135,9 +136,22 @@ def std_shell_pipe(args): if idx == len(args.items) - 1: stdout = None lst = arg.value.split(" ") - ret = subprocess.run(lst, stdout=stdout, input=prev) - prev = ret.stdout - return NebBool(True) + if prev is None: + if stdout is None: + ret = subprocess.run(lst, capture_output=True) + else: + ret = subprocess.run(lst, stdout=stdout) + else: + if stdout is None: + ret = subprocess.run(lst, input=prev.stdout, capture_output=True) + else: + ret = subprocess.run(lst, stdout=stdout, input=prev.stdout) + + # 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) def evaluate_expression(expr): if not expr.symbol.name in STD: @@ -239,9 +253,9 @@ def build_std(): STD["->string"] = [to_string] # shell - shell_string = FuncImpl(NebFunction("$", [NebString], NebBool), std_shell) + shell_string = FuncImpl(NebFunction("$", [NebString], NebList), std_shell) STD["$"] = [shell_string] - shell_pipe = FuncImpl(NebFunction("$|", [NebList], NebBool), std_shell_pipe) + shell_pipe = FuncImpl(NebFunction("$|", [NebList], NebList), std_shell_pipe) STD["$|"] = [shell_pipe] build_std() |
