From 5f019f545a7214c0c7c6cc8d789886ebfcb93eba Mon Sep 17 00:00:00 2001 From: mryouse Date: Fri, 13 May 2022 04:19:38 +0000 Subject: add a shell-pipe command --- std.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'std.py') diff --git a/std.py b/std.py index 1bb20d4..30d81c9 100644 --- a/std.py +++ b/std.py @@ -124,7 +124,19 @@ def std_literal_to_string(arg): # shell def std_shell(arg): assert isinstance(arg, NebString) - subprocess.run(arg.value) + lst = arg.value.split(" ") + subprocess.run(lst) + return NebBool(True) + +def std_shell_pipe(args): + prev = None + stdout = subprocess.PIPE + for idx, arg in enumerate(args.items): + 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) def evaluate_expression(expr): @@ -229,5 +241,7 @@ def build_std(): # shell shell_string = FuncImpl(NebFunction("$", [NebString], NebBool), std_shell) STD["$"] = [shell_string] + shell_pipe = FuncImpl(NebFunction("$|", [NebList], NebBool), std_shell_pipe) + STD["$|"] = [shell_pipe] build_std() -- cgit v1.2.3