王路 发表于 2006-7-28 21:08:15

求助:如何在c程序中获得shell的返回值

需要获得一个进程的进程号,采用she l l 调用来完成.但是无法将匹配的数字传回C程序

我的程序如下 :
#include <stdio.h>
#include <sys/stat.h>
#include <string.h>
#include <errno.h>

main()
{
      int pid;
      pid=system("ps -ef | grep linphonec|awk '{print $4}'");
      printf("The pid is %d\n",pid);
}

sunwen 发表于 2006-7-29 09:59:28

use popen
页: [1]
查看完整版本: 求助:如何在c程序中获得shell的返回值