如何从C执行bash命令? [重复]

时间:2021-10-19 01:15:43

This question already has an answer here:

这个问题在这里已有答案:

Is there a way to run command line utilities, e.g. gzip, into a C app?

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

1 个解决方案

#1


18  

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系统)。

By the way, this question already has an answer here: How do I execute external program within C code in linux with arguments?

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

#1


18  

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系统)。

By the way, this question already has an answer here: How do I execute external program within C code in linux with arguments?

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