发布网友 发布时间:2022-04-25 15:53
共1个回答
热心网友 时间:2023-10-14 22:40
用“这是读的例子(popen的参数决定是读还是写),这个例子运行一个程序并获得程序的输出:void ShowPS(){char buf[1024];FILE * pf;sprintf(buf,"ps aux | head -1 ; ps aux | grep %ld | sort -rn +4 | head -1",getpid());string cmd=buf;if(NULL==(pf=popen(cmd.c_str(),"r"))){thelogreturn;}thelogwhile(NULL.=fgets(buf,1024,pf)){theLog}theLogpclose(pf);return;}