int cmd(char* cmd, char* result)
{
char buffer[10240];
FILE* pipe = popen(cmd, "r");
if (!pipe)
return -1;
while(!feof(pipe)) {
if(fgets(buffer, 4096, pipe)){
strcat(result, buffer);
}
}
pclose(pipe);
return 0;
}
int main()
{
char buffer[10240]="";
if(cmd("ps", buffer) == 0)
printf("cmd ps output : %s\n", buffer);
return 0;
}
C语言获取命令行输出
最新推荐文章于 2025-03-11 13:49:47 发布