Yes. You use pipes. Each process has two standard streams - stdout and stderr. These are just io streams. They could map to files, or to console pipes. When you spawn the new process, you set the new processes output pipes to redirect to file handles on the controlling process. From there you can do whatever you like. You could for example, read the child processes pipes and push their output to the controlling processes output pipes.
In windows you do it like this:
#define SHANDLE HANDLE
bool CmdShell::makePipe( SHANDLE& read, SHANDLE& write )
{
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof( SECURITY_ATTRIBUTES );
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = true;
SHANDLE writeTmp;
if ( !CreatePipe( &read, &writeTmp, &sa, 0 ))
{
assert(0);
return false;
}
if ( !DuplicateHandle( GetCurrentProcess(), writeTmp,
GetCurrentProcess(), &write, 0,
FALSE, DUPLICATE_SAME_ACCESS ))
{
assert(0);
return false;
}
CloseHandle( writeTmp );
return true;
}
On linux you do it like this:
#define SHANDLE int
bool CmdShell::makePipe( SHANDLE& read, SHANDLE& write )
{
s32 pipeD[2];
if ( pipe( pipeD ))
{
assert(0);
return false;
}
read = pipeD[0];
write = pipeD[1];
return true;
}