Is there anyway to set stdout and stderr for a spawned process?
  Home FAQ Contact Sign in
comp.os.mswindows.programmer.win32 only
 
Advanced search
POPULAR GROUPS

more...

 Up
Is there anyway to set stdout and stderr for a spawned process?         

Group: comp.os.mswindows.programmer.win32 · Group Profile
Author: Subrahmanya
Date: Apr 29, 2008 00:47

Hi All

Does any one has idea about how to set stdout and stderr to a spawned
process in windows?

I don't want to have all the handles of the parent process in the
child process but I want only one of it (handle to a file). If I
inherit all the handles of the parent process my application won't
work. So I am spawning a process without inheriting the handles but I
am inheriting environment variables. Later I take the PID of the
spawned process and using Openprocess() function I get the process
handle and I generate a duplicate file handle for the child process
with an existing file handle. Now I am trying to set STDOUT and STDERR
using SetStdHandle() function. The code I wrote is below:

ACE_Process_Options* procOptions;
procOptions->setCommandLine(m_sCommandLine);

ACE_HANDLE hTmpFile = ACE_OS::open(m_sStdOutErrFile, O_WRONLY|
O_CREAT);
HANDLE hTmpDupFile;

procOptions->setHandles(ACE_INVALID_HANDLE, hTmpFile,
hTmpFile);
pid = pOSMonitor->spawnProcess(m_pProcess, procOptions);
if (pid > 0){
HANDLE procHandle = OpenProcess(PROCESS_ALL_ACCESS, PM_FALSE,
pid);
DuplicateHandle(GetCurrentProcess(), hTmpFile, procHandle,
&hTmpDupFile, 0, PM_FALSE, DUPLICATE_SAME_ACCESS);
procOptions->setHandles(ACE_INVALID_HANDLE,
(ACE_HANDLE)hTmpDupFile, (ACE_HANDLE)hTmpDupFile);
SetStdHandle(STD_OUTPUT_HANDLE, hTmpDupFile);
SetStdHandle(STD_ERROR_HANDLE, hTmpDupFile);
CloseHandle(procHandle);
}

ACEOS::close(hTmpFile);

But when I execute my application the standard output and standard
error are not written to the file pointed by the file handle
'hTmpDupFile'.

Am I missing anything here?

Thanks in advance
Subrahmanya
1 Comment
diggit! del.icio.us! reddit!

RELATED THREADS
SubjectArticles qty Group
Re: Send stderr to variable, but send stdout to screen?linux.debian.user ·