Skip to content

Commit bf49996

Browse files
committed
CHANGE: modified launch function not to use shell and to handle all optional script arguments
1 parent 76ce93b commit bf49996

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

src/mezz/mezz-control.reb

+20-11
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,29 @@ REBOL [
1111
}
1212
]
1313

14-
launch: func [
14+
launch: function/with [
1515
{Runs a script as a separate process; return immediately.}
16-
script [file! string! none!] "The name of the script"
17-
/args arg [string! block! none!] "Arguments to the script"
16+
script [file! string!] "The name of the script"
17+
/with args [string! block! none!] "Arguments to the script"
1818
/wait "Wait for the process to terminate"
19-
/local exe
2019
][
21-
if file? script [script: to-local-file any [to-real-file script script]]
22-
exe: to-local-file system/options/boot
23-
24-
; Quote everything, just in case it has spaces:
25-
args: to-string reduce [{"} exe {" "} script {" }]
26-
if arg [append args arg]
27-
either wait [call/wait/shell args] [call/shell args]
20+
command: reduce [system/options/boot script]
21+
if args [
22+
unless block? args [args: reduce [:args]]
23+
foreach arg args [
24+
;; arguments are expected to be strings...
25+
append command escape-arg mold/flat arg
26+
]
27+
]
28+
sys/log/info 'REBOL ["Launch:" as-green reform next command]
29+
call/:wait command
30+
][
31+
;-- just a simple argument escaping function
32+
;@@ needs test on other platforms... Linux seems to be ok without any escaping.
33+
escape-arg: func[arg] either/only system/platform = 'Windows [
34+
replace/all arg #"^"" {\"}
35+
append insert arg #"^"" #"^""
36+
][ arg ]
2837
]
2938

3039
wrap: func [

src/tests/units/call-test.r3

+9
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ rebol-cmd: func[cmd][
127127
--assert 0:0:2 < delta-time [do %units/files/launch-wait.r3] ;; should wait
128128
--assert 6 = try [length? read/lines %units/files/launched.txt] ;; 6 because 3x launched!
129129

130+
--test-- "do launch/with"
131+
--assert all [
132+
file? write %args.r3 {Rebol[] args: system/options/args forall args [args/1: transcode/one args/1] save %temp args}
133+
0 == launch/with/wait %args.r3 args: [2 {a "b" c} %"foo space"]
134+
args == load %temp
135+
]
136+
delete %temp
137+
delete %args.r3
138+
130139
try [delete %units/files/launched.txt]
131140
===end-group===
132141

0 commit comments

Comments
 (0)