首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

linux c system函数调用命令,怎么得到显示信息

2012-03-23 
linux c system函数调用命令,如何得到显示信息。#include stdio.h#include stdlib.hmain(){char url[10

linux c system函数调用命令,如何得到显示信息。
#include <stdio.h>
#include <stdlib.h>

main()
{
  char url[1024] = {0};
  char command[512] = {0};
  char result[2024] = {0};
  strcpy(command, "ifconfig eth0");
  system(command);
}


linux c system函数,返回的整形数值,如何得到待执行的命令ifconfig eth0 返回的信息,并赋给一变量。
或者有没有其他函数或方法能够得到命令显示的信息?

[root@localhost taskSplit]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr XX:A9:XX:39:44:XX  
  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  RX packets:8401087 errors:0 dropped:0 overruns:0 frame:0
  TX packets:8699464 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:1000 
  RX bytes:6003800449 (5.5 GiB) TX bytes:4497202637 (4.1 GiB)
  Interrupt:50 Base address:0x2000 


[解决办法]
man popen
[解决办法]
下面程序在我机器上运行时直接打印输出 ifconfig 所有信息了。
等同于在 bash 下运行 ifconfig.

C/C++ code
intmain(void){  system("ifconfig");    return 0;}
[解决办法]
探讨

man popen

[解决办法]
popen 正解

热点排行