Commit 079f5dc1 authored by Maxim Velesyuk's avatar Maxim Velesyuk

Add input redirection, add parameters escaping

parent 2b13cdbd
......@@ -44,6 +44,14 @@ Will output:
errors: pwd: ignoring non-option arguments
Input:
a: [4 2 5 7 1 6 7 1 9]
probe shell/run [sort < a]
Outputs:
["1" "1" "2" "4" "5" "6" "7" "7" "9"]
## Debugging:
......
......@@ -31,16 +31,22 @@ shell-command: object [
stdout: {}
stderr: {}
exit-code: none
run: func [] [
run: func [ /local cmd ] [
exit-code: 0
if external [
forall arguments [
if file? arguments/1 [ arguments/1: to-string arguments/1 ]
if string? arguments/1 [
; replace arguments/1 {'} {\'}
insert append arguments/1 {'} {'}
]
]
cmd: reform [command arguments]
exit-code: either stdin [
call/wait/input/output/error reform [command arguments] stdin stdout stderr
if block? stdin [ stdin: reform-lines stdin ]
call/wait/input/output/error cmd stdin stdout stderr
] [
call/wait/output/error reform [command arguments] stdout stderr
call/wait/output/error cmd stdout stderr
]
]
]
......@@ -97,11 +103,19 @@ shell: context [
command-list
]
run: func [block /raw /debug /local cmd out-buffer err-buffer ret redirects] [
run: func [block /raw /debug /local cmd out-buffer err-buffer ret redirects inpt] [
clear command-list
either parse block rules/complete-command [
forall command-list [
cmd: command-list/1
if inpt: find cmd/redirects '< [
inpt: inpt/2
if string? inpt [ inpt: to-file inpt ]
cmd/stdin: case [
file? inpt [ read inpt ]
word? inpt [ get inpt ]
]
]
if out-buffer [ cmd/stdin: out-buffer ]
if error? ret: try [ cmd/run ] [
cmd/exit-code: -666
......@@ -186,7 +200,8 @@ shell: context [
; probe shell/run/debug [ls -a | grep "red" >> var && pwd > %file.txt]
; probe shell/run/debug [ls / | sort -r | grep {doesnt-exist}]
; a: [4 2 5 7 1 6 7 1 9]
; probe shell/run/debug [sort < a]
; probe shell/run [true || echo "nothing"]
; probe shell/run [true && echo "test"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment