regarding system function

Discussion in 'Python' started by praba kar, Apr 22, 2005.

  1. praba kar

    praba kar Guest

    Dear All,

    In Php If I send a command to system function
    then It will return 1 on success and 0 on failure. So
    based upon that value I can to further work.

    But In Python If I send a command to system
    function then It will return 0 only for both
    conditions(success and failure). So What I need
    to do for this. I want the result like php system
    function.


    regards
    Prabahar


    ________________________________________________________________________
    Yahoo! India Matrimony: Find your life partner online
    Go to: http://yahoo.shaadi.com/india-matrimony
     
    praba kar, Apr 22, 2005
    #1
    1. Advertising

  2. praba kar

    Mike Meyer Guest

    praba kar <> writes:

    > Dear All,
    >
    > In Php If I send a command to system function
    > then It will return 1 on success and 0 on failure. So
    > based upon that value I can to further work.
    >
    > But In Python If I send a command to system
    > function then It will return 0 only for both
    > conditions(success and failure). So What I need
    > to do for this. I want the result like php system
    > function.


    You don't say what platform you're on, but from your description of
    the problem, it's not Unix:

    py> os.system("grep foo /dev/null")
    256
    py> os.system("grep foo /no_such_file")
    grep: /no_such_file: No such file or directory
    512

    os.system is a simple wrapper around the C system() function. It's
    return value is the same as that function. On unix, that's the 1/0 you
    want in the upper byte, and status information in the lower byte - so
    you divide by 256. I have no idea what Windows does in this case.

    I'd recommend using the subprocess routines instead of os.system. They
    are much more powerful/flexible than os.system.

    <mike
    --
    Mike Meyer <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
     
    Mike Meyer, Apr 22, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mantorok
    Replies:
    0
    Views:
    364
    Mantorok
    Aug 18, 2005
  2. AG
    Replies:
    8
    Views:
    343
    Andrew Poelstra
    Apr 23, 2006
  3. sunil

    Regarding system function

    sunil, Oct 6, 2006, in forum: C Programming
    Replies:
    12
    Views:
    439
    Richard Bos
    Oct 9, 2006
  4. Benny Van
    Replies:
    4
    Views:
    374
    zeppe
    Apr 20, 2007
  5. Usman Ghani
    Replies:
    0
    Views:
    161
    Usman Ghani
    Apr 17, 2006
Loading...

Share This Page