File tree 2 files changed +29
-11
lines changed
2 files changed +29
-11
lines changed Original file line number Diff line number Diff line change @@ -11,20 +11,29 @@ REBOL [
11
11
}
12
12
]
13
13
14
- launch : func [
14
+ launch: function /with [
15
15
{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"
18
18
/wait "Wait for the process to terminate"
19
- /local exe
20
19
][
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 ]
28
37
]
29
38
30
39
wrap : func [
Original file line number Diff line number Diff line change @@ -127,6 +127,15 @@ rebol-cmd: func[cmd][
127
127
--assert 0:0:2 < delta-time [do %units/files/launch-wait.r3 ] ;; should wait
128
128
--assert 6 = try [length? read /lines %units/files/launched.txt ] ;; 6 because 3x launched!
129
129
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
+
130
139
try [delete %units/files/launched.txt ]
131
140
===end-group===
132
141
You can’t perform that action at this time.
0 commit comments