barry <> 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?
>
> Is there a fix for this or am i misunderstanding something fundamental
> about
> the way the system() call works in msc5.0? (Like the command.com always
> returning the 0, which system(), in turn, returns to my program?)
>
> I'm trying to determine whether or not the executed command succeeded or
> not by
> looking at the completion code from system, ala:
>
> char buf[BUFSIZ];
>
> sprintf(buf,"rnews < D_elricf.3aa");
> if (!system(buf)) perror(buf);
>
> and i'm having a hard time of it since system() always (seems) to return
> 0!
<joke>But 0! is 1.</joke>
How sure are you that "rnews < D_elricf.3aa" is returning a
non-zero status? It might just be a problem with rnews command.
If so, there's not much that system() can do about it.
All the standard says about this is:
If the argument is not a null pointer, and the system function
does return, it returns an implementation-defined value.
It may be reasonable to assume, on your particular implementation,
that the result returned by system() is related to the exit status
of the invoked program. But you should check your implementation's
documentation. The input redirection might have some effect on the
handling of the exit status; for example, I can imagine that you
might be getting the status of the command processor that invoked
the command "rnews < D_elricf.3aa" rather than the status of the
"rnews" command.
If there is a problem with your implementation's system()
function, you'll need to ask about it in a forum that deals with
your implementation, perhaps comp.os.ms-windows.programmer.win32
or one of the microsoft.* groups.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"