S
subrahmanya
Hi All
Does any one has idea about how to set stdout and stderr to a spawned
process?
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:
pen(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
Does any one has idea about how to set stdout and stderr to a spawned
process?
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:
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