Using system() or other, how do I get the return value of a program?
example:
printf( “%d”, system( “program” ) );
I want to output what program would return.
Using system() or other, how do I get the return value of a program?
example:
printf( “%d”, system( “program” ) );
I want to output what program would return.
Look at pipes/dup etc or use popen().
-Adam
Doug Rixmann <rixmannd@rdsdata.com> wrote in message
news:b32s4g$gco$1@inn.qnx.com…
Using system() or other, how do I get the return value of a program?
example:
printf( “%d”, system( “program” ) );
I want to output what program would return.
\
Adam Mallory <amallory@qnx.com> wrote:
Look at pipes/dup etc or use popen().
-Adam
Doug Rixmann <> rixmannd@rdsdata.com> > wrote in message
news:b32s4g$gco$> 1@inn.qnx.com> …
Using system() or other, how do I get the return value of a program?example:
printf( “%d”, system( “program” ) );
I want to output what program would return.
Keep in mind that only the low order 8 bits (1 byte) is available as
return status.
I never understood why main() is documented as returning an int when
only a char is available. But QNX has claimed several times that they
are doing the right thing. I.E. It ain’t a bug it’s a feature!
–
Bill Caroselli – Q-TPS Consulting
1-(626) 824-7983
qtps@earthlink.net
Bill Caroselli <qtps@earthlink.net> wrote in message
news:b33aaj$1u2$1@inn.qnx.com…
Keep in mind that only the low order 8 bits (1 byte) is available as
return status.
You mean the exit status.
I never understood why main() is documented as returning an int when
only a char is available. But QNX has claimed several times that they
are doing the right thing. I.E. It ain’t a bug it’s a feature!
We are. Just the exit status is coded into the 8 bits, the other status
components are also encoded in that int. Also ANSI/ISO C99 mandates that
main() return an int.
– snip–
5.1.2.2.1 Program startup
1 The function called at program startup is named main. The implementation
declares no
prototype for this function. It shall be defined with a return type of int
and with no
parameters:
int main(void) { /* … */ }
or with two parameters (referred to here as argc and argv, though any names
may be
used, as they are local to the function in which they are declared):
int main(int argc, char argv[]) { / … */ }
or equivalent;9) or in some other implementation-defined manner.
–snip–
-Adam
Doug Rixmann <rixmannd@rdsdata.com> wrote:
Using system() or other, how do I get the return value of a program?
example:
printf( “%d”, system( “program” ) );
I want to output what program would return.
You need to use the WEXITSTATUS() macro, as documented in the
docs for the system() function.
Note: as stated elsewhere, only the bottom 8 bits is available.
(Yes, that is mandated behaviour, also coded into that int is
how the thing died (signal, normal termination, etc and if signal,
what signal terinated it, … see docs for wait() and the various
macros for examining this.)
Note: system() runs a shell that runs your program – if you don’t
need the shell, using one of the spawn*() family of functions will
be much lighter. (e.g. spawnl().)
QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.
Adam Mallory <amallory@qnx.com> wrote:
Bill Caroselli <> qtps@earthlink.net> > wrote in message
news:b33aaj$1u2$> 1@inn.qnx.com> …Keep in mind that only the low order 8 bits (1 byte) is available as
return status.You mean the exit status.
I never understood why main() is documented as returning an int when
only a char is available. But QNX has claimed several times that they
are doing the right thing. I.E. It ain’t a bug it’s a feature!We are. Just the exit status is coded into the 8 bits, the other status
components are also encoded in that int. Also ANSI/ISO C99 mandates that
main() return an int.
I do understand. I agree that QNX is doing what the rules say.
I just disagree with the rules. But then again it wouldn’t be a day
of the week that ends in ‘y’ if I didn’t disagree with someone’s rules.
Bill Caroselli <qtps@earthlink.net> wrote in message
news:b33qoi$i8m$2@inn.qnx.com…
I do understand. I agree that QNX is doing what the rules say.
That’s not what I understood. When you said:
“But QNX has claimed several times that they are doing the
right thing. I.E. It ain’t a bug it’s a feature!”
I took that to mean you didn’t believe it was the correct behaviour.
I just disagree with the rules. But then again it wouldn’t be a day
of the week that ends in ‘y’ if I didn’t disagree with someone’s rules.
One could always come up with their own standard, get an international
consortium to back it and then publish the specifications. Or just go
the cheaper route and make an RFC for the new environment - could prove
interesting.
-Adam