21

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

2
  • why not just use the c library for (de)compression (zlib)? Commented Apr 20, 2015 at 23:31
  • 1
    If 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. Commented Apr 21, 2015 at 4:30

1 Answer 1

42

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?

Sign up to request clarification or add additional context in comments.

3 Comments

See: Why to avoid system() function in c/c++. Instead look at the execl family of functions.
man system # seems to default to 3
No entry for system in section 1 of the manual No entry for system in section 2 of the manual so starts at 3

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.