<span style="font-size:24px;">#include<stdio.h>
#include<string.h>
void execmd(char *cmd,char *result)
{
char buffer[128] = {0};//定义一个字符串缓冲区
//创建一个管道执行命令
FILE *pipe = _popen(cmd,"r");
if(pipe == NULL)
{
printf("运行失败");
return;
}
else
{
//判断是否到了文件末尾
while(!feof(pipe))
{
if(fgets(buffer,128,pipe))
{
//保存到result中
strcat(result,buffer);
}
}
_pclose(pipe);
return;
}
}
void main()
{
char output[1024*8] = {0};
execmd("tasklist",output);
if(strstr(output,"QQ.exe"))
{
printf("exist\n");
}
else
{
printf("not exist");
}
//printf("%s\n",output);
system("pause");
}</span>