Skip to content

Commit

Permalink
CHANGE: modified launch function not to use shell and to handle all…
Browse files Browse the repository at this point in the history
… optional script arguments
  • Loading branch information
Oldes committed Nov 30, 2023
1 parent 76ce93b commit bf49996
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/mezz/mezz-control.reb
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,29 @@ REBOL [
}
]

launch: func [
launch: function/with [
{Runs a script as a separate process; return immediately.}
script [file! string! none!] "The name of the script"
/args arg [string! block! none!] "Arguments to the script"
script [file! string!] "The name of the script"
/with args [string! block! none!] "Arguments to the script"
/wait "Wait for the process to terminate"
/local exe
][
if file? script [script: to-local-file any [to-real-file script script]]
exe: to-local-file system/options/boot

; Quote everything, just in case it has spaces:
args: to-string reduce [{"} exe {" "} script {" }]
if arg [append args arg]
either wait [call/wait/shell args] [call/shell args]
command: reduce [system/options/boot script]
if args [
unless block? args [args: reduce [:args]]
foreach arg args [
;; arguments are expected to be strings...
append command escape-arg mold/flat arg
]
]
sys/log/info 'REBOL ["Launch:" as-green reform next command]
call/:wait command
][
;-- just a simple argument escaping function
;@@ needs test on other platforms... Linux seems to be ok without any escaping.
escape-arg: func[arg] either/only system/platform = 'Windows [
replace/all arg #"^"" {\"}
append insert arg #"^"" #"^""
][ arg ]
]

wrap: func [
Expand Down
9 changes: 9 additions & 0 deletions src/tests/units/call-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ rebol-cmd: func[cmd][
--assert 0:0:2 < delta-time [do %units/files/launch-wait.r3] ;; should wait
--assert 6 = try [length? read/lines %units/files/launched.txt] ;; 6 because 3x launched!

--test-- "do launch/with"
--assert all [
file? write %args.r3 {Rebol[] args: system/options/args forall args [args/1: transcode/one args/1] save %temp args}
0 == launch/with/wait %args.r3 args: [2 {a "b" c} %"foo space"]
args == load %temp
]
delete %temp
delete %args.r3

try [delete %units/files/launched.txt]
===end-group===

Expand Down

0 comments on commit bf49996

Please sign in to comment.