[C++] socket -9[匿名管道]

 

::怎么弄都不能读取信息....先把代码放着....

 1 #include<windows.h>
 2 #include<stdio.h>
 3 int main()
 4 {
 5     HANDLE read=NULL,write=NULL;
 6     SECURITY_ATTRIBUTES ss;
 7     STARTUPINFO sa={0};
 8     PROCESS_INFORMATION pp={0};
 9     char text[]="匿名管道程序测试!";
10     DWORD writetext;
11     ss.nLength=sizeof(ss);
12     ss.lpSecurityDescriptor=NULL;
13     ss.bInheritHandle=TRUE;
14     if(CreatePipe(&read,&write,&ss,0))
15     {
16         printf("创建匿名管道成功!\r\n");
17         sa.cb=sizeof(sa);
18         sa.dwFlags=STARTF_USESHOWWINDOW;
19         sa.hStdInput=read;
20         sa.hStdOutput=write;
21         sa.hStdError=GetStdHandle(STD_ERROR_HANDLE);
22         if(::CreateProcess(NULL,"子进程.exe",NULL,NULL,TRUE,0,NULL,NULL,&sa,
23             &pp))
24         {
25             printf("创建子进程成功\r\n");
26             WriteFile(write,text,sizeof(text),&writetext,NULL);
27             printf("通过匿名管道写入数据成功\r\n");
28         }
29         else
30         {
31             printf("创建子程失败\r\n");
32         }
33     }
34     //::Sleep(50000);
35     return 0;
36 }
 1 #include<windows.h>
 2 #include<stdio.h>
 3 int main()
 4 {
 5     HANDLE read=NULL;
 6     char text[100]={0};
 7     DWORD readtext;
 8     read=GetStdHandle(STD_INPUT_HANDLE);
 9     if(ReadFile(read,text,100,&readtext,NULL))
10     {
11         printf("从匿名管道读取的数据是: %s\r\n",text);
12     }
13     else
14     {
15         printf("读取失败!\r\n");
16     }
17     ::Sleep(10000);
18     return 0;
19 }

 

posted @ 2014-04-27 12:17  beautifulzzzz  阅读(738)  评论(0编辑  收藏  举报