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

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::eek: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
 
O

osama178

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::eek: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


Try asking in this group: comp.os.ms-windows.programmer.win32
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top