亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 1133 | 回復(fù): 0
打印 上一主題 下一主題

[C] 請(qǐng)幫我看個(gè)popen,pclose的報(bào)錯(cuò) [復(fù)制鏈接]

論壇徽章:
13
CU大;照
日期:2013-03-14 14:14:082016科比退役紀(jì)念章
日期:2016-07-22 11:15:35數(shù)據(jù)庫(kù)技術(shù)版塊每日發(fā)帖之星
日期:2016-05-27 06:20:002015亞冠之吉達(dá)阿赫利
日期:2015-08-05 10:06:542015年亞洲杯之韓國(guó)
日期:2015-04-01 16:05:42雙魚(yú)座
日期:2014-11-13 11:04:24丑牛
日期:2014-07-25 17:29:54子鼠
日期:2014-04-25 12:25:45丑牛
日期:2014-04-17 08:35:48巨蟹座
日期:2014-04-16 16:50:05CU大牛徽章
日期:2013-03-14 14:14:29CU大牛徽章
日期:2013-03-14 14:14:26
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2016-09-01 21:25 |只看該作者 |倒序?yàn)g覽
我看了這里的代碼,錯(cuò)的離譜的很啊
http://crasseux.com/books/ctutorial/Programming-with-pipes.html#Programming%20with%20pipes

  1. SYNOPSIS
  2.        #include <stdio.h>

  3.        ssize_t getline(char **lineptr, size_t *n, FILE *stream);

  4.        ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
復(fù)制代碼
getdelim 的原型第三個(gè)參數(shù)是int, 這里面怎么能用 "\n\n" 2個(gè)換行做分割。

我改了下這個(gè)代碼,還是不對(duì),關(guān)鍵是我還不知道錯(cuò)在哪里,請(qǐng)大家指點(diǎn)下。

  1. #define _GNU_SOURCE
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <errno.h>
  5. #include <string.h>

  6. int main()
  7. {
  8.     FILE *ps_pipe;
  9.     FILE *grep_pipe;

  10.     size_t bytes_read;
  11.     size_t nbytes=100;
  12.     char *my_string;

  13.     //open our two pipes
  14.     ps_pipe=popen("ps -A","r");
  15.     grep_pipe=popen("grep init","w");

  16.     //check that pipes are non-null,therefore open
  17.     if((!ps_pipe) || (!grep_pipe)){
  18.         fprintf(stderr,"One or both pipes failed.\n");
  19.         return EXIT_FAILURE;
  20.         }

  21.     //read from ps_pipe until two newlines
  22.     my_string=(char *)malloc(nbytes+1);
  23.     bytes_read=getline(&my_string,&nbytes,ps_pipe);
  24.    
  25.     int errno;
  26.     //closing ps_pipe,checking for errors
  27.     if(pclose(ps_pipe)!=0){
  28.         perror("Could not run 'ps', or other error.\n");
  29.         }

  30.     //send output of 'ps -A' to 'grep init' with two newlines
  31.     fprintf(grep_pipe, "%s\n",my_string);
  32.    
  33.     int ret;
  34.     char error[100];
  35.     //close grep_pipe,checking for errors
  36.     if((ret=pclose(grep_pipe))!=0){
  37.         printf("ret is %d",ret);
  38.         perror("pclose()");
  39.         printf("the pclose errored with %s",strerror(ret));
  40.         }

  41.     return 0;
  42.     }
復(fù)制代碼
現(xiàn)在運(yùn)行報(bào)錯(cuò)是這個(gè)
  1. pclose(): Success
  2. ret is 256the pclose errored with Unknown error 256
復(fù)制代碼


您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP