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

Adrien Nader adrien at notk.org
Tue Sep 1 14:08:47 BST 2015


Hi,

On Tue, Sep 01, 2015, Leonardo Laguna wrote:
> 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?

Yes! I'm not saying it will happen, only that it's possible.

It's probably the kind of things for which you need to provide new
testsuite entries.
Have you checked the compatibility for this? I.e. is it supposed to also
work on Windows XP? (not that I care about XP)
You will also need to explain the possible drawbacks of passing NULL as
the first parameter.

Just a few quick ideas. If this solves the problem you mention, that
sounds like something good but at the same time the corresponding code
is quite sensitive and with Microsoft's weird APIs I'm a bit worried
about corner cases.

-- 
Adrien Nader


More information about the wg-windows mailing list