Skip to content

Commit

Permalink
Merge pull request #29 from nojb/windows_maybe_quote
Browse files Browse the repository at this point in the history
Windows: use quoting heuristic from the compiler
  • Loading branch information
aalekseyev authored Apr 18, 2022
2 parents 49e54ca + 0a6117b commit e159092
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/spawn.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ external spawn_windows :
-> stderr:Unix.file_descr
-> int = "spawn_windows_byte" "spawn_windows"

let maybe_quote f =
if
String.contains f ' ' || String.contains f '\"' || String.contains f '\t'
|| f = ""
then
Filename.quote f
else
f

let spawn_windows ~env ~cwd ~prog ~argv ~stdin ~stdout ~stderr ~use_vfork:_
~setpgid:_ =
let cwd =
Expand All @@ -120,7 +129,7 @@ let spawn_windows ~env ~cwd ~prog ~argv ~stdin ~stdout ~stderr ~use_vfork:_
| Fd _ -> invalid_arg "Spawn.spawn: [cwd=Fd _] is not supported on Windows"
| Inherit -> None
in
let cmdline = String.concat (List.map argv ~f:Filename.quote) ~sep:" " in
let cmdline = String.concat (List.map argv ~f:maybe_quote) ~sep:" " in
let prog =
match (Filename.is_relative prog, cwd) with
| true, Some p -> Filename.concat p prog
Expand Down

0 comments on commit e159092

Please sign in to comment.