
Emulov's stupid questions: nr 24
I quoted the answer from the C FAQ before. Here it is again:
19.27: How can I invoke another program (a standalone executable, or an
operating system command) from within a C program?
A: Use the library function system(), which does exactly that.
Note that system's return value is at best the command's exit
status (although even that is not guaranteed), 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.
You really, really should download your own copy. When you have a question,
pop it into your favorite editor and search for some key words in the
expression about which you have a question. You are probably as smart or
smarter than I am. So you can find this stuff as fast or faster than I can.
Then you won't have to wait around for a message on usenet.
If you want better results, you will need an OS specific trick. The popen()
stuff on UNIX is way superior to anything that I know of on PC's.
--
Hypertext C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-FAQ ftp: ftp://rtfm.mit.edu, C-FAQ Book: ISBN 0-201-84519-9
Try "C Programming: A Modern Approach" ISBN 0-393-96945-2
Want Software? Algorithms? Pubs? http://www.infoseek.com
Quote:
>Does the system() function return a value?
>Let's say that I use system("del c:\\somedir\\*.*"); in a dos-environment
>for example. Then how would i know if the operation was successful or not?
>--
>Hey, I speak for myself. No _nagging_ afterwards...
>remove NOSPAM when replying
>-
>http://www.sin.khk.be/~emulov/index_english.htm
>computer, internet, programming, search engines