views:

311

answers:

3

Hello all,I have my main application ,from my main application I will be calling another module(third party) to perform a small operation in my main application,when I call that module..it processes for a particular time say 5 sec.while its proccessing it shows the process in the commmand window with some information..now my main application waits until the called module finishes its process.Now my Question is..how to do I hide this command window without disturbing its process..I tried to use the createprocess but it seems to not work...

for example: my main application is the Parent process and the called application is child process..Parent process should be independent of the child process..check my example below

int main()
{
  execl("c:\\users\\rakesh\\Desktop\\calledapplication.exe","c:\\users\\rakesh\\Desktop    \\calledapplication.exe",0);


}

code in calledapplication
int main
{
  printf("Rakesh");
}

now considering the above if you run the first program...output would appear in the same command window(It shouldnt be like that)...I want the main application to create the process but it should not be affected by child process.

+2  A: 

Pass CREATE_NO_WINDOW in the dwCreationFlags parameter of CreateProcess.

James McNellis
@Rakesh - having no console window displayed for a process is quite a different request than somehow forcing a program to not be able to display a message box it's programmed to display. You should clarify in your question exactly what you're trying to do so people aren't guessing or solving the wrong problem
Michael Burr
check my edit michael
kiddo
A: 

It sounds like you want the child process's output to show up in a separate window. If so, you want to call CreateProcess and pass it the CREATE_NEW_CONSOLE flag, rather than using exec*.

Gabe
A: 

You talked about a "command window", so I presume that the child is a console application. In that case you can create the process in a separate conole and optionally force the new console to be iconified or hidden. The following code launch a child process that interprets a batch file (mytest.bat). I hope it can help. Regards.

#include <windows.h>
#include <stdio.h>

int main(int argc, char **argv)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL rv = FALSE;
WCHAR cmdline[] = TEXT("cmd.exe /c mytest.bat");

    memset(&si,0,sizeof(si));
    si.cb = sizeof(si);
// Add this if you want to hide or minimize the console
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_HIDE; //or SW_MINIMIZE
///////////////////////////////////////////////////////
    memset(&pi,0,sizeof(pi));
    rv = CreateProcess(NULL, cmdline, NULL, NULL,
                           FALSE, CREATE_NEW_CONSOLE,
                           NULL, NULL, &si, &pi);
    if (rv) {
        WaitForSingleObject(pi.hProcess, INFINITE);
                printf("Done! :)\n");
    }
        else {
                printf("Failed :(\n");

    }

        return rv ? 0 : 1;
}
Giuseppe Guerrini