Is there a way to run command line utilities, e.g. gzip
, into a C app?
Asked
Active
Viewed 1e+01k times
21

tarabyte
- 17,837
- 15
- 76
- 117
-
why not just use the c library for (de)compression (zlib)? – jayhendren Apr 20 '15 at 23:31
-
1If you run it as a "bash command", a la system(), you're doing it wrong. Direct invocation with an exec-family syscall is more efficient and less prone to bugs. – Charles Duffy Apr 21 '15 at 04:30
1 Answers
41
Use 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.
By the way, this question already has an answer here: How do I execute external program within C code in linux with arguments?

Community
- 1
- 1

jayhendren
- 4,286
- 2
- 35
- 59
-
3See: [**Why to avoid system() function in c/c++**](http://stackoverflow.com/questions/19913446/why-to-avoid-system-function-in-c-c). Instead look at the `execl` family of functions. – David C. Rankin Apr 21 '15 at 04:28
-
-
No entry for system in section 1 of the manual No entry for system in section 2 of the manual so starts at 3 – jasonleonhard Feb 12 '21 at 04:43