How to avoid cmd.exe console window when calling system() 
Author Message
 How to avoid cmd.exe console window when calling system()

Hi all,

I am trying to do some direct Windows2000 system calls from MFC. I am using
the C-Function "system" to do this. This works in principle. However, when I
do it a cmd.exe console window pops up and disappears again as soon as the
system call is completed.

Any ideas how to avoid this?
Daniel



Sun, 20 Feb 2005 22:19:40 GMT  
 How to avoid cmd.exe console window when calling system()

Quote:

> Hi all,

> I am trying to do some direct Windows2000 system calls from MFC. I am using
> the C-Function "system" to do this. This works in principle. However, when I
> do it a cmd.exe console window pops up and disappears again as soon as the
> system call is completed.

> Any ideas how to avoid this?
> Daniel

Use the API call CreateProcess instead
this has a hide option, replace sTemp with your command options

        STARTUPINFO theStartUpInfo;
        FillMemory(&theStartUpInfo, sizeof(STARTUPINFO), 0);
        theStartUpInfo.cb = sizeof(STARTUPINFO);
        // use the wShowWindow property
        theStartUpInfo.dwFlags = STARTF_USESHOWWINDOW;
        theStartUpInfo.wShowWindow =  SW_HIDE; // hide the window

        PROCESS_INFORMATION theProcessInformation;
        FillMemory(&theProcessInformation, sizeof(PROCESS_INFORMATION), 0);

        // run the program
        int iSuccess = CreateProcess(NULL, // should be exe name but it won't
run perl that way :-(
                                                                                                const_cast<char*>(sTemp.c_str()),
                                                                                                NULL,
                                                                                                NULL,
                                                                                                FALSE,
                                                                                                CREATE_NEW_PROCESS_GROUP | NORMAL_PRIORITY_CLASS,
                                                                                                NULL,
                                                                                                NULL,
                                                                                                &theStartUpInfo,
                                                                                                &theProcessInformation);



Sun, 20 Feb 2005 22:43:20 GMT  
 How to avoid cmd.exe console window when calling system()
CreateProcess is what you need.

Best regards,
yhhuang
VS.NET, Visual C++
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net?  http://www.gotdotnet.com



Mon, 21 Feb 2005 09:25:00 GMT  
 How to avoid cmd.exe console window when calling system()
Thank you both for your input. CreateProcess or WinExex, respectively, seems
to work fine. But I have a follow-up problem: How can I wait for the process
to be completed, before resuming execution of my main application?

Thanks in advance,

Daniel



Quote:
> CreateProcess is what you need.

> Best regards,
> yhhuang
> VS.NET, Visual C++
> Microsoft

> This posting is provided "AS IS" with no warranties, and confers no
rights.
> Got .Net?  http://www.gotdotnet.com



Mon, 21 Feb 2005 15:43:03 GMT  
 How to avoid cmd.exe console window when calling system()

Quote:

> Thank you both for your input. CreateProcess or WinExex, respectively, seems
> to work fine. But I have a follow-up problem: How can I wait for the process
> to be completed, before resuming execution of my main application?

You need to use a wait
WaitForSingleObject(theProcessInformation.hProcess, 1000);
The second arg is the timeout interval, use -1 for infinite

        Vin



Mon, 21 Feb 2005 17:19:32 GMT  
 How to avoid cmd.exe console window when calling system()
See the following KB article for an example.

        Q131775 - HOWTO: Access Child Process Exit Code from 32-Bit Parent
Process

--
Cheers
Check Abdoul
----------------



Quote:
> Thank you both for your input. CreateProcess or WinExex, respectively,
seems
> to work fine. But I have a follow-up problem: How can I wait for the
process
> to be completed, before resuming execution of my main application?

> Thanks in advance,

> Daniel



> > CreateProcess is what you need.

> > Best regards,
> > yhhuang
> > VS.NET, Visual C++
> > Microsoft

> > This posting is provided "AS IS" with no warranties, and confers no
> rights.
> > Got .Net?  http://www.gotdotnet.com



Mon, 21 Feb 2005 23:10:21 GMT  
 How to avoid cmd.exe console window when calling system()
In Win32 programming, the id of process can be treated as an event under
some situation. We can use WaitForSingleObject(hProcess...) to wait for its
exit.

Best regards,
yhhuang
VS.NET, Visual C++
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net?  http://www.gotdotnet.com



Tue, 22 Feb 2005 11:42:47 GMT  
 How to avoid cmd.exe console window when calling system()
Everything works perfect now.

Thanx to all of you,
Daniel



Quote:
> In Win32 programming, the id of process can be treated as an event under
> some situation. We can use WaitForSingleObject(hProcess...) to wait for
its
> exit.

> Best regards,
> yhhuang
> VS.NET, Visual C++
> Microsoft

> This posting is provided "AS IS" with no warranties, and confers no
rights.
> Got .Net?  http://www.gotdotnet.com



Tue, 22 Feb 2005 15:21:25 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Prevent cmd.exe popup on system call

2. How to call BAT or CMD via system()?

3. retrieving text from CMD.EXE window

4. How to eliminate cmd.exe window flash

5. getting rid of the cmd.exe window

6. hidden window created by system(cmd)

7. avoid console window during debugging

8. Calling a 16-bit system DLL from my 32-bit exe

9. How to call B.exe from A.exe and then stop A.exe

10. Tell me if an exe is a console or windows program

11. Tell me if an exe is a console or windows program

12. Writing a CMD.exe replacement..

 

 
Powered by phpBB® Forum Software