Problems using CreateProcess and sending StdOut to a file

I have an application that uses CreateProcess to launch 1 or more child processes. These processes take command line arguments to configure them, and that all seems to work fine.

The problems I am having is that I want to redirect the StdOut and StdErr output from the command line application to a (log) file. I am using CreateFile to create a file handle that is passes to CreateProcess. I see the file getting created on, but nothing ever gets written to the file.

The C++ that I am using is as follows...

if ((g_Options.m_stdOut2File == true) && (sLog != ""))
{
m_hOut = CreateFileA
(
m_sLog.c_str(),
GENERIC_WRITE,
(FILE_SHARE_READ | FILE_SHARE_WRITE),
NULL,
OPEN_ALWAYS,
0,
NULL
);
}

STARTUPINFO siStartInfo;

memset(&siStartInfo, 0, sizeof(STARTUPINFO));

siStartInfo.cb = sizeof(STARTUPINFO);

siStartInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
siStartInfo.wShowWindow = (rcDesc.m_visible ? SW_SHOW : SW_HIDE);
siStartInfo.hStdInput = m_stdIN.readH();

if (sLog != "" && m_hOut != NULL)
{
siStartInfo.hStdError = m_hOut;
siStartInfo.hStdOutput = m_hOut;
}
else
{
siStartInfo.hStdError = m_stdERR.writeH();
siStartInfo.hStdOutput = m_stdOUT.writeH();
}

bool bStatus =
::CreateProcess
(
rcDesc.m_sExecPath.c_str(),
pParamBuf,
NULL,
NULL,
TRUE,
CREATE_NO_WINDOW,
NULL,
rcDesc.m_sStartupPath.c_str(),
&siStartInfo,
&m_PI
);

Topic archived. No new replies allowed.