Reputation: 987
I'm using CreateProcess()
from a console program to run another console program, but it runs in the same window as the first one.
STARTUPINFO sinfo;
PROCESS_INFORMATION pinfo;
LPSTR commandLine = " \"Cows and Bulls.exe\" test ";
ZeroMemory(&sinfo, sizeof(sinfo));
ZeroMemory(&pinfo, sizeof(pinfo));
if(!CreateProcess(0,commandLine, 0, 0, FALSE, 0, 0, 0, &sinfo, &pinfo))
cout << "failed";
This is my code. What am I doing wrong? It gets really fun when I add a
for(int i=0; true; i++)
{
cout << i;
Sleep(1000);
}
to the first one. Then it starts outputting the numbers IN the next one.
It's like the two programs are merged.. I don't want that, i want to open a new window.
P.S. I'm passing arguments, yes, but if I cut the test
the result's the same.
Upvotes: 1
Views: 895
Reputation: 61307
To give the child process a new console you need to set the CREATE_NEW_CONSOLE
flag in the dwCreationFlags
argument of your call to CreateProcess
. Documentation here: http://msdn.microsoft.com/en-gb/library/windows/desktop/ms682425(v=vs.85).aspx
Upvotes: 5