摘抄:https://blog.youkuaiyun.com/u010299133/article/details/85637263
主要有三种方法:exec函数簇,system函数以及popen函数,其中需要注意的是,exec函数簇的函数执行成功后是无返回的,一般需要和fork()函数同时使用。在使用时需要另外的fork一个进程。 popen() 函数通过创建一个管道,调用 fork 产生一个子进程,执行一个 shell 以运行命令来开启一个进程。这个进程必须由 pclose() 函数关闭,而不是 fclose() 函数。
exec函数簇:
函数原型:
#include <unistd.h>
extern char **environ;
int execl(const char *path, const char *arg, ...
/* (char *) NULL */);
int execlp(const char *file, const char *arg, ...
/* (char *) NULL */);
int execle(const char *path, const char *arg, .