Return value of created process by using 'create process'

HI All,

I am facing a problem in capturing the return value of the process that is created by create process

My code goes like this :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
if(CreateProcessA(NULL,
		(LPSTR)w.c_str(),
		NULL,
		NULL,
		FALSE,
		0,
		NULL,
		NULL,
		&si,
		&pi)== false)
	{
	printf("Create process failed(%d).\n",GetLastError());
        iReturnVal = GetLastError();
	printf ("The value returned by the process was: %d.\n",iReturnVal);
	}
	else
	{
	// Wait until child process exits.
	WaitForSingleObject( pi.hProcess, time );
	printf ("The value returned was: %d.\n",time);
	printf ("The value returned by the process was: %d.\n",iReturnVal);
	cout << endl;		
	}


here when the process creation fails then i get the return value in iReturnval.

But when the create process succeeds i.e I usually run some exe file or cmd prompt file in create process function which returns some value after successful/fail conditions. and i have to take actions according to those return values.

please help me to catch return values of the processes created.

Any help is welcome
Thx.. in advance
Namrata
Last edited on
This depends entirely on the process you are running. Most built in Windows processes don't return anything useful. If you are running your own program with this function then handling the value returned has more to do with the way THAT program executes.

How about a run down about what you are trying to do exactly? Your description so far is painfully vauge.
Pass pi.hProcess to GetExitCodeProcess.
Hi computergeek 01,

Ya i understand that...I try to explain a bit more here..
I have a csv file which have few exe or cmdline options ..
I have to run these files one by one and take the desision according too the return value of thease files..

what i did is creation of the processes and passing the parsed values to the create process.
Now..the processes are being created fine..and i can see the results on the cmd prompt.

But i also want to capture the return Value of these executed process. i.e the exe file running by the "create process"..

for eg..if i make a simple c++ file to return -2...when i run the exe of this c++ program form my create process function..i should be in a position to catch (-2)

Thanks for the reply anyway
Nam
kbw is right and that is a text book answer. But I have a feeling that you want more data then just what is returned by GetExitCodeProcess(). The data returned might be useless to you which is why I'm digging for more detail. If you are trying to process information that would be displayed on the monitor by a system command for example you would need to pipe that somewhere.

EDIT: In that case it looks like kbw has your answer.
Last edited on
Hi computergeek 01

Thanks for the quick response, And sorry for my late response.
Well the solution by kbw solved my problem..i had few problems though ..but somehow i managed to solve them all...

Thanks kbw also..

Nam
Remember to close the process and thread handles in pi. cmd.exe in Daytona Gold leaked them and eventually fell over because of that.
Topic archived. No new replies allowed.