为什么通过popen函数返回的值与直接在shell里输入命令的返回值不同?
#defineCMD"ifconfig|grepdsr|awk'{print$1}'"intget_protocol_info(){intproto_index=0;ch...
#define CMD "ifconfig|grep dsr|awk '{print $1}'"
int get_protocol_info()
{
int proto_index = 0;
char buf[12];
FILE *fp;
if ((fp = (FILE *)popen(CMD, "r")) == NULL)
{
printf("popen() error!\n");
exit(1);
}
fgets(buf, 5, fp);
pclose(fp);
printf("buf=%s\n",buf);
} 展开
int get_protocol_info()
{
int proto_index = 0;
char buf[12];
FILE *fp;
if ((fp = (FILE *)popen(CMD, "r")) == NULL)
{
printf("popen() error!\n");
exit(1);
}
fgets(buf, 5, fp);
pclose(fp);
printf("buf=%s\n",buf);
} 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询