Я создал новый процесс и перенаправил его стандартный вывод в текстовый файл, он работает.
STARTUPINFO si;
PROCESS_INFORMATION pi;
SECURITY_ATTRIBUTES sa;
HANDLE hOutFile;
ZeroMemory( &si, sizeof(si) );
ZeroMemory( &pi, sizeof(pi) );
ZeroMemory( &sa, sizeof(sa) );
si.cb = sizeof(si);
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES ;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = true;
// Create output file and get file handle
hOutFile = CreateFile ( TEXT(outFilePath.c_str()),
FILE_SHARE_WRITE,
0,
&sa, // provide SECURITY_ATTRIBUTES
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
// Assign StartInfo StdOutput to file handle
si.hStdOutput = hOutFile ;
LPTSTR szCmdline = TEXT( command.c_str() );
if( !CreateProcess( NULL, // No module name (use command line)
szCmdline, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
true, // Set handle inheritance to TRUE
0, // No creation flags
NULL, // Use parent's environment block
TEXT(jarSignerExeDir.c_str()), // Use jarSignerExeDir FOR starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
ShowMessage( "CreateProcess failed (%d).\n" + GetLastError() );
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process,thread and file handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
CloseHandle(hOutFile);