New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unix.create_process fails to call .bat scripts with spaces in path given arguments with spaces #6978
Comments
Comment author: @diml I tried something similar but couldn't reproduce the issue. Here is what I tried: $ cat echo_args.ml let pid = let _ = Unix.waitpid [] pid |
Comment author: modlfo Hi, here are more detailed steps of what I'm doing to reporduce the problem. 1.- Create a dir "C:\Path With Spaces" Name: echoargs.batecho %1
|
Comment author: @xavierleroy This one is mysterious. The MSDN page says that the first parameter lpApplicationName can be NULL, in which case the beginning of the command-line determines the application name. But nowhere it says that a non-NULL lpApplicationName can cause problems with spaces in file names... Indeed, the "Security Remarks" section of the MSDN page cautions against passing NULL as lpApplicationName. Any Windows expert here to help us understand? |
Comment author: @xavierleroy I can reproduce the problem when the executable is a .bat batch file, but not when it is a proper .exe executable. I'm not even sure that the Win32 CreateProcess() system call is supposed to handle .bat files as executables. The examples I found on the Web involve calling cmd.exe as executable and "/c" "foo.bat" as arguments. Resolving this PR as "not an OCaml issue". |
Original bug ID: 6978
Reporter: modlfo
Status: resolved (set by @xavierleroy on 2017-02-20T13:25:56Z)
Resolution: not a bug
Priority: normal
Severity: minor
Version: 4.02.3
Target version: undecided
Category: platform support (windows, cross-compilation, etc)
Monitored by: @gasche @diml @hcarty @alainfrisch
Bug description
[ Original summary was: Unix.create_process fails to call programs with spaces in path given arguments with spaces ]
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.
Steps to reproduce
See the example in the description
Additional information
I have found a solution for it.
When calling CreateProcess the first argument needs to be NULL
CreateProcess(NULL",""C:/some.exe" arg1 arg2",.........);
Rather than:
CreateProcess("C:/some.exe",""C:/some.exe" arg1 arg2",.........);
Here's the documentation https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx
I saw that Qt qprocess does the same, which makes me think that this change is stable and well tested.
https://github.com/Vitallium/qt5/blob/master/qtbase/src/corelib/io/qprocess_win.cpp
The text was updated successfully, but these errors were encountered: