Ive been trying to understand this subject for two days now, but can't seem to get it working. My setup is two consoles, a Server console, and a server message board console. The Server message board is a child process of my Server console. The Server will send messages to the Server message board for output.
AKA Server detects error, sends the error message to the server message board to output to console screen.
Server
HANDLE _pipeRead;
HANDLE _pipeWrite;
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = true;
sa.lpSecurityDescriptor = 0;
if(!CreatePipe(&_pipeRead, &_pipeWrite, &sa, 0))
{
int error = GetLastError();
std::cout << GetLastError();
}
PROCESS_INFORMATION pi;
STARTUPINFO si;
ZeroMemory(&si,sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdOutput = _pipeRead;
si.hStdInput = _pipeWrite;
si.hStdError = _pipeWrite;
if(!CreateProcess("Child.exe", 0, 0, 0, true, CREATE_NEW_CONSOLE, 0, 0, &si, &pi))
{
int error = GetLastError();
std::cout << "Error: " << error;
}
while(true)
{
DWORD bytesSent = 0;
WriteFile(_pipeWrite, "Test Message", strlen("Test Message"), &bytesSent, 0);
}
Server message board
char msgBuffer[25];
DWORD bytesRead = 0;
while(true)
{
ReadFile(GetStdHandle(STD_INPUT_HANDLE), msgBuffer, 25, &bytesRead, 0);
printf(msgBuffer);
}
I would expect that I would see the message "Test Message" being repeated on the Server Message Board console.
Can anyone clear things up?