即使我之前调用了CreateNamedPipe,我仍然挂在WaitNamedPipe函数上。由于waitnamedpipe函数只是等待管道的启动,为什么呢?代码如下。谢谢
PROCESS_INFORMATION po;
STARTUPINFO
s;
GetStartupInfo (&s);
if(CreateProcess ("c:\s2.exe", NULL, NULL, NULL, false, 0, NULL,
NULL, &s, &po) == FALSE)
{
printf("Error %d starting CC\n",
GetLastError());
exit(-1);
}
HANDLE pipe=CreateNamedPipe (pipe_name, 0x00000003,
FILE_FLAG_FIRST_PIPE_INSTANCE,
PIPE_UNLIMITED_INSTANCES,128, 128, 0,
NULL);
while(WaitNamedPipe(pipe_name, INFINITE)==FALSE) Sleep(300);
HANDLE CC = CreateFile (pipe_name, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
NULL);
bool fConnected = ConnectNamedPipe(pipe, NULL) ? TRUE :
(GetLastError() ==
ERROR_PIPE_CONNECTED);
if(fConnected) printf("true");
else printf("false");
答案 0 :(得分:1)
"C:\s2.exe"
不是"C:\\s2.exe"