Richard Heathfield <rj*@see.sig.invalidwrites:
rudra said:
>i have written a code::
#include <stdio.h>
#include <stdlib.h>
int main()
{
int sys;
int i686;
sys=system("/bin/uname -m");
//printf ("%d",sys);
if (sys==i686){
Since the defined-but-not-initialised i686 int object doesn't have a value,
how can this comparison be meaningful? I think what you're really trying
to do is find out whether the output of uname is the string "i686", but
the return value of the system() function won't tell you this.
One possibility for achieving your objective is to redirect the output of
the command to a file, and then open and read the file. This would keep
the code reasonably portable. An alternative that you might wish to
explore if you're into system-specific stuff is a pipe (and
comp.unix.programmer knows all about pipes).
Portability is a tricky thing. The call system("/bin/uname -m") is
portable in the sense that it uses a function defined by the C
standard, but it will fail unless the string "/bin/uname -m" happens
to be meaningful as a command.
As it happens, any system on which "/bin/uname -m" is a valid command
will have other methods to achieve the same result, using non-portable
functions. <OT>Using a pipe should work, but invoking the underlying
uname() function directly is cleaner and really no less portable.</OT>
Let me repeat the excellent advice to post to comp.unix.programmer.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <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"