system() always returns 0?

Wietse Z. Venema wietse at wzv.UUCP
Wed Jan 25 06:53:44 AEST 1989


In article <782 at hawkmoon.MN.ORG> det at hawkmoon.MN.ORG (Derek E. Terveer) writes:
>Has anyone encountered a problem with the Microsoft C 5.0 compiler always
>returning a 0 from the system() call, no matter what the actual command
>executed by system() returns?

Command.com always returns a zero status. There are two alternatives:

(a) Do not use a shell, but use the spawnlp() functions. These are
    similar to the unix execlp() functions, but instead of over-
    laying the calling process they just suspend it.

(b) Use a different shell. This may not be practical if your program
    is to be used on other machines.

In case of alternative (a) you will have to do your own i/o redirection
handling.  Caveat:  in some cases I had to save the positions of all
stdio streams open for reading from files, and restore them after the
system() routine terminated.
-- 
work:	wswietse at eutrc3.uucp	| Eindhoven University of Technology
work:	wswietse at heitue5.bitnet	| Mathematics and Computing Science
home:	wietse at wzv.uucp		| 5600 MB Eindhoven, The Netherlands



More information about the Comp.lang.c mailing list