Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] Howto execute a command without the "cmd" windows opening?

3 views
Skip to first unread message

Matthieu Dubuget

unread,
Nov 4, 2009, 6:15:58 AM11/4/09
to caml...@inria.fr
Hello,

I'm trying to run a separated program from an ocaml program (linked with
"-subsystem windows" flexlink option). I'm using mingw flavour of Ocaml.

The program to run separately is also an ocaml program, linked with
"-subsystem windows".

The problem is that a "c:\windows\system32\cmd.exe" windows pops up: I'd
like to avoid this.

I tried Sys.command and Unix.system without success.

Is there any way to run a program and get the process status without
using cmd.exe ?

Thanks

Matt

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

David Allsopp

unread,
Nov 4, 2009, 6:22:55 AM11/4/09
to matthieu...@gmail.com, caml...@inria.fr
> The problem is that a "c:\windows\system32\cmd.exe" windows pops up:
> I'd like to avoid this.

Both Sys.command and Unix.system use cmd in order to provide command line
parsing (it gives the closest equivalent to the Unix version - except for
the usual quoting weirdness of cmd as compared to bash!)

> I tried Sys.command and Unix.system without success.
>
> Is there any way to run a program and get the process status without
> using cmd.exe ?

It's been on my todo list to wrap the CreateProcess Win32 API function[1] in
a C stub function - someone else may have done this (possibly in
ocaml-win32[2] or something like that), though. The API is very simple (most
parameters will be NULL) so the stub would not take long to write.


David

[1] http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx
[2] http://caml.inria.fr/cgi-bin/hump.en.cgi?contrib=371

Matthieu Dubuget

unread,
Nov 4, 2009, 6:24:47 AM11/4/09
to David Allsopp, caml...@inria.fr

> It's been on my todo list to wrap the CreateProcess Win32 API function[1] in
> a C stub function - someone else may have done this (possibly in
> ocaml-win32[2] or something like that), though. The API is very simple (most
> parameters will be NULL) so the stub would not take long to write.
>
>
Thank you David. I'll go this way, then.

Matt

Matthieu Dubuget

unread,
Nov 4, 2009, 6:54:30 AM11/4/09
to caml...@inria.fr

>> It's been on my todo list to wrap the CreateProcess Win32 API function[1] in
>> a C stub function - someone else may have done this (possibly in
>> ocaml-win32[2] or something like that), though. The API is very simple (most
>> parameters will be NULL) so the stub would not take long to write.
>>
>>
>>
> Thank you David. I'll go this way, then.
>
> Matt
>

If i find a way to read the exit status of the process…

David Allsopp

unread,
Nov 4, 2009, 7:04:58 AM11/4/09
to matthieu...@gmail.com, caml...@inria.fr
> If i find a way to read the exit status of the process…

Pass a PROCESS_INFORMATION structure to CreateProcess (in order to get the hProcess for the process you created) and then use GetExitCodeProcess[1]. You can use WaitForSingleObject passing hProcess to it if you need to block until the process has actually terminated or you can loop on GetExitCodeProcess until the result is not equal to STILL_ACTIVE.


David


[1] http://msdn.microsoft.com/en-us/library/ms683189(VS.85).aspx
[2] http://msdn.microsoft.com/en-us/library/ms687032(VS.85).aspx

Adrien

unread,
Nov 4, 2009, 7:05:33 AM11/4/09
to caml...@inria.fr
That's a bit hackish but you can also try to change the COMSPEC
environment variable which points to cmd.exe by default.

---

Adrien Nader

Alain Frisch

unread,
Nov 4, 2009, 7:22:12 AM11/4/09
to matthieu...@gmail.com, caml...@inria.fr
Matthieu Dubuget wrote:
> Is there any way to run a program and get the process status without
> using cmd.exe ?

Did you try Unix.create_process?

Alain

Matthieu Dubuget

unread,
Nov 4, 2009, 8:58:40 AM11/4/09
to Alain Frisch, caml...@inria.fr
-------- Message original --------
Sujet : Re: [Caml-list] Howto execute a command without the "cmd"
windows opening?
De : Alain Frisch <al...@frisch.fr>
Pour : matthieu...@gmail.com
Date : Wed Nov 04 2009 13:22:01 GMT+0100 (CET)

> Matthieu Dubuget wrote:
>> Is there any way to run a program and get the process status without
>> using cmd.exe ?
>
> Did you try Unix.create_process?
>
> Alain
>
>
Thanks to Alain and David.

Something like


Unix.waitpid []
(Unix.create_process
external_prog args
Unix.stdin Unix.stdout Unix.stderr)

does it.

Salutations

Matt

0 new messages