私はとを使用するプログラムを持っていpopen
ますpclose
:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/wait.h>
int main(void)
{
FILE *fp = NULL;
int ret_val = 0;
fp = popen("ls *", "r");
if (NULL == fp)
{
printf("popen error\n");
return 1;
}
ret_val = pclose(fp);
if (-1 == ret_val)
{
printf("pclose error\n");
return 1;
}
else
{
printf("%d,%d,%d\n",ret_val, WIFEXITED(ret_val), WEXITSTATUS(ret_val));
}
return 0;
}
プログラムの出力は次のとおりです。
./test
Broken Pipe
36096,1,141
私の質問は次のとおりです。
- なぜ「壊れたパイプ」があるのですか?
- 終了ステータスコード141はなぜですか?「ls*」は正常に実行されたと思うので、終了ステータスは0である必要があります。