#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
void my_system(const char *cmd)
{
char result[10240] = {0};
char buf[1024] = {0};
FILE *fp = NULL;
if( (fp = popen(cmd, "r")) == NULL ) {
printf("popen error!\n");
return;
}
while (fgets(buf, sizeof(buf), fp)) {
strcat(result, buf);
}
pclose(fp);
printf("result: %s\n", result);
}
int main(int argc, char const *argv[])
{
my_system("adb devices");
my_system("ls -l");
return 0;
}
C实现system函数,获取执行的结果
最新推荐文章于 2024-06-21 21:45:09 发布