C语言 如何从 C 执行 bash 命令?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29762189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to execute bash commands from C?
提问by tarabyte
Is there a way to run command line utilities, e.g. gzip, into a C app?
有没有办法在gzipC 应用程序中运行命令行实用程序?
回答by jayhendren
Use system():
使用system():
#include <stdlib.h>
int status = system("gzip foo");
See the man page (man 3 system) for more detailed information on how to use it.
有关man 3 system如何使用它的更多详细信息,请参阅手册页 ( )。
By the way, this question already has an answer here: How do I execute external program within C code in linux with arguments?
顺便说一下,这个问题在这里已经有了答案:How do I execute external program within C code in linux in with arguments?

