如何从C执行bash命令?

tar*_*yte 14 c bash gzip

有没有办法运行命令行实用程序,例如gzip,进入C应用程序?

jay*_*ren 25

用途system():

#include <stdlib.h>
int status = system("gzip foo");
Run Code Online (Sandbox Code Playgroud)

有关man 3 system如何使用它的更多详细信息,请参见手册页().

顺便说一下,这个问题已经有了答案:如何使用参数在linux中的C代码中执行外部程序?

  • 请参阅:[**为什么要避免使用c/c ++中的system()函数**](http://stackoverflow.com/questions/19913446/why-to-avoid-system-function-in-cc).而是查看`execl`系列函数. (3认同)