Is there a way to run command line utilities, e.g. gzip, into a C app?
-
why not just use the c library for (de)compression (zlib)?jayhendren– jayhendren2015-04-20 23:31:54 +00:00Commented Apr 20, 2015 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– Charles Duffy2015-04-21 04:30:43 +00:00Commented Apr 21, 2015 at 4:30
Add a comment
|
1 Answer
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?
3 Comments
David C. Rankin
See: Why to avoid system() function in c/c++. Instead look at the
execl family of functions.jasonleonhard
man system # seems to default to 3jasonleonhard
No entry for system in section 1 of the manual No entry for system in section 2 of the manual so starts at 3