
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);