I have a simple console app providing me with some pre-build functionality in Visual Studio 2010. It goes on to spawn other child processes (though waits for the termination of those child processes.
When I run the app outside visual studio all its messages, etc, appear in the console window (ie stdout). However when I run this app under VS then I don’t see any of the output in the build window.
Does anybody know why this is?
Its very annoying.
Edit: On further inspection I have managed to get the stdout of my app to appear but the stdout of the child processes are not appearing. Any ideas?
I re-direct the stdout of the child processes using the following code:
STARTUPINFO si;
GetStartupInfo( &si );
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdError = GetStdHandle( STD_ERROR_HANDLE );
si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
si.hStdOutput = GetStdHandle( STD_OUTPUT_HANDLE );
PROCESS_INFORMATION pi;
// Create the process.
if ( !CreateProcess( applicationName.GetCStr(), cmd.CStr(), NULL, NULL, TRUE, 0, NULL, workingDir.GetCStr(), &si, &pi ) )
{
// Failed to create process!!
return false;
}
I believe you need to make explicit handles for the child process to hook them up. MSDN has an article on it (or several), see http://msdn.microsoft.com/en-us/library/ms682499%28v=vs.85%29.aspx for example.
Child processes inherit open object handles, but have their own stdin/stdout/etc. handles, unless you go through the proper hoops to create them explicitly for it. That’s my understanding, anyway; read the article for more info.