### Question 19.27

How can I invoke another program (a standalone executable, or an operating system command) from within a C program?

Use the library function `system`, which does exactly that. Note that `system`'s return value is the command's exit status, and usually has nothing to do with the output of the command. Note also that `system` accepts a single string representing the command to be invoked; if you need to build up a complex command line, you can use `sprintf`. See also question 19.30.

References: K&R1 Sec. 7.9 p. 157
K&R2 Sec. 7.8.4 p. 167, Sec. B6 p. 253
ANSI Sec. 4.10.4.5
ISO Sec. 7.10.4.5
H&S Sec. 19.2 p. 407
PCS Sec. 11 p. 179

Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995 // mail feedback