aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--std.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/std.py b/std.py
index 30d81c9..1786aa5 100644
--- a/std.py
+++ b/std.py
@@ -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()