[wg-windows] Problem (and fix) with Unix.create_process in windows

Leonardo Laguna modlfo at gmail.com
Tue Sep 1 14:01:55 BST 2015


Hi,

I have spent some hours trying to find a problem when using
Unix.create_process in windows.

The problem shows when trying to create a process in which the path of the
executable and one of the arguments have spaces, for example:

let cmd = "C:/Program Files/Something/something.exe" ;;
let args = ["arg1"; "arg2"; "C:/Program Files/arg3"] ;;

let pid = Unix.create_process cmd (cmd::args |> Array.of_list) Unix.stdin
Unix.stdout Unix.stderr ;;

Unix.waitpid [] pid ;;

As soon as there's an argument with spaces, the process fails to run. I
tried many different combinations with quoting, backlashes, forwardslashes,
backslashed space, etc, but nothing seemed to work.

I saw that ocaml calls CreateProcess from the windows API, which has many
weird things in the documentation.

When calling CreateProcess you need to supply (optionally) the path to the
application and then the full command line call. For example:

CreateProcess("C:/some.exe","\"C:/some.exe\" arg1 arg2",.........);

Note that you need to pass in the full command line the name of the
application quoted.

The only way of fixing my problem was to pass NULL as first argument:

CreateProcess(NULL","\"C:/some.exe\" arg1 arg2",.........);

After making this change all calls work fine for me.

Has anyone had these kind of problems?

Is is possible to get this change in the ocaml code?

Leonardo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ocaml.org/pipermail/wg-windows/attachments/20150901/bd4fd452/attachment.html>


More information about the wg-windows mailing list