(2007-03の一覧)
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
2007-03-07 Wed (他の年の同じ日: 2004)
外部プログラムの標準出力を取得する
2007-03-07-1 / カテゴリ: [programming][c] / [permlink]
popen(3) を使う。
#include <stdio.h>
int main() {
FILE *fp = NULL;
char buf[1024];
fp = popen("ls", "r");
if (fp == NULL) {
printf("fp == NULL\n");
return 1;
}
while (fgets(buf, sizeof(buf), fp)) {
printf("[%s]", buf);
}
pclose(fp);
return 0;
}
↑この場合、ls の出力の各行末の改行は付いたまま。[
コメント ]
2013 : 01 02 03 04 05 06 07 08 09 10 11 12
2012 : 01 02 03 04 05 06 07 08 09 10 11 12
2011 : 01 02 03 04 05 06 07 08 09 10 11 12
2010 : 01 02 03 04 05 06 07 08 09 10 11 12
2009 : 01 02 03 04 05 06 07 08 09 10 11 12
2008 : 01 02 03 04 05 06 07 08 09 10 11 12
2007 : 01 02 03 04 05 06 07 08 09 10 11 12
2006 : 01 02 03 04 05 06 07 08 09 10 11 12
2005 : 01 02 03 04 05 06 07 08 09 10 11 12
2004 : 01 02 03 04 05 06 07 08 09 10 11 12
最終更新時間: 2013-05-02 16:12
