Howto execute a command without the "cmd" windows opening?

View: New views
8 Messages — Rating Filter:   Alert me  

Howto execute a command without the "cmd" windows opening?

by Matthieu Dubuget :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

RE: Howto execute a command without the "cmd" windows opening?

by David Allsopp :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> 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

_______________________________________________
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

Re: Howto execute a command without the "cmd" windows opening?

by Matthieu Dubuget :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> 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

_______________________________________________
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

Re: Howto execute a command without the "cmd" windows opening?

by Matthieu Dubuget :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


>> 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…

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

RE: Howto execute a command without the "cmd" windows opening?

by David Allsopp :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> 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

_______________________________________________
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

Re: Howto execute a command without the "cmd" windows opening?

by Camarade_Tux :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

_______________________________________________
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

Re: Howto execute a command without the "cmd" windows opening?

by Alain Frisch-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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


_______________________________________________
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

Re: Howto execute a command without the "cmd" windows opening?

by Matthieu Dubuget :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-------- Message original --------
Sujet : Re: [Caml-list] Howto execute a command without the "cmd"
windows opening?
De : Alain Frisch <alain@...>
Pour : matthieu.dubuget@...
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

_______________________________________________
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