diff options
| author | mryouse | 2022-05-13 04:19:38 +0000 |
|---|---|---|
| committer | mryouse | 2022-05-13 04:19:38 +0000 |
| commit | 5f019f545a7214c0c7c6cc8d789886ebfcb93eba (patch) | |
| tree | cc62936206df80797fd73a181e81103c31b2ace8 /std.py | |
| parent | bb3bb065d57546370451dd9579cbad2f08758108 (diff) | |
add a shell-pipe command
Diffstat (limited to 'std.py')
| -rw-r--r-- | std.py | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -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() |
