1
可能重复:
Best way to capture stdout from a system() command so it can be passed to another function获取系统()的输出到一个变量
在linux下获得服务的当前状态,我写了这个代码段::
char cmd[100];
sprintf(cmd,"service %s status",argv[1]);
system(cmd);
它运行良好,它显示控制台上的输出如下:mysql正在运行或mysql已停止
但我需要在控制台输出一个字符串变量。如何在字符串变量中获得“mysql正在运行”,以便稍后可以使用该字符串变量。 thankx。