关于匿名管道的一段代码?
为什么我不能读到数据呢?
#include <stdio.h>
#include <windows.h>
int main()
{
HANDLE hWrite,hRead,hTmp;
if (!CreatePipe(&hRead,&hWrite,NULL,0))
{
printf("创建管道失败!\n");
}
hTmp = GetStdHandle(STD_OUTPUT_HANDLE);
SetStdHandle(STD_OUTPUT_HANDLE,hWrite);
STARTUPINFO myStartup;
PROCESS_INFORMATION myInfo;
GetStartupInfo(&myStartup);
BOOL hReturn;
hReturn = CreateProcess("..\\logger\\debug\\logger.exe",
NULL,NULL,NULL,TRUE,
CREATE_NEW_CONSOLE,
NULL,NULL,&myStartup,&myInfo);
SetStdHandle(STD_OUTPUT_HANDLE,hTmp);
if (!hReturn)
{
printf("创建进程失败!\n");
}
CloseHandle(hWrite);
char readBuf[100];
DWORD bytesRead = 0;
while(ReadFile(hRead,readBuf,100,&bytesRead,NULL))
{
readBuf[bytesRead] = '\0';
printf("Read %d Bytes from pipe[%s]",bytesRead,readBuf);
}
CloseHandle(hRead);
return 0;
}
//process logger.exe
#include <stdio.h>
#include <iostream.h>
int main(int argc, char* argv[])
{
int i;
for(i =0; i<10; i++)
{
printf("Logging %d\n",i);
cout<<"Output Line:"<<i<<endl;
cerr<<"Error Line:"<<i<<endl;
}
return 1;
}