system call as variabe

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rudra

    system call as variabe

    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){
    printf("the syst. 32 bit");
    }
    else
    printf("64but") ;
    }
    where i want the output of "system("/bin/uname -m")" as the variable
    sys.....to find the machine structure.this procedure is not quite
    working. can you people suggest me some way?
  • Ian Collins

    #2
    Re: system call as variabe

    rudra wrote:
    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){
    printf("the syst. 32 bit");
    }
    else
    printf("64but") ;
    }
    where i want the output of "system("/bin/uname -m")" as the variable
    sys.....to find the machine structure.this procedure is not quite
    working. can you people suggest me some way?
    Lack of whitespace in the code?

    The serious answer is system() does not return the value printed by the
    command you pass to it.

    Check your man pages, then ask about popen() on comp.unix.progr ammer.

    --
    Ian Collins.

    Comment

    • viza

      #3
      Re: system call as variabe

      On Tue, 08 Jul 2008 22:21:39 -0700, rudra wrote:
      sys=system("/bin/uname -m");
      Systems which provide a uname program will probably provide a uname
      system call or library function. Lookup:

      man 2 uname (on Linux)
      man 3 uname (on BSD)

      (just "man uname" will get you the manual page for the uname(1), which is
      the application)

      Comment

      Working...