capturing system exit status

Discussion in 'Python' started by oscartheduck, Apr 2, 2007.

  1. oscartheduck

    oscartheduck Guest

    Hi folks,

    in a program I'm writing I have several commands I pass to the unix OS
    underneath the code.

    I want to perform error checking to make sure that the OS commands'
    exit gracefully, but I'm not seeing a simple python module to do this.
    The closest I can see is system(), as detailed here:
    http://www.python.org/doc/2.1.3/lib/os-process.html, but I can't
    formulate a way to use it.

    What I want is a simple if statement such that:

    if ExitStatusIsBad:
    sys.exit()
    else:
    go on to next code chunk
     
    oscartheduck, Apr 2, 2007
    #1
    1. Advertising

  2. oscartheduck wrote:

    > in a program I'm writing I have several commands I pass to the unix OS
    > underneath the code.
    >
    > I want to perform error checking to make sure that the OS commands'
    > exit gracefully, but I'm not seeing a simple python module to do this.


    If you're using Python 2.5, you can use subprocess.check_call() which
    will raise CalledProcessError for nonzero exit code. If you're using
    Python 2.4, you can use retcode = subprocess.call() and check it yourself.
    --
    Michael Hoffman
     
    Michael Hoffman, Apr 2, 2007
    #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. Tim F.
    Replies:
    1
    Views:
    556
    Joe Smith
    Jan 29, 2004
  2. =?Utf-8?B?Qm9iIEtlbGxlcg==?=

    Returning/Capturing the status of a checkbox in a gridview (V2.0)

    =?Utf-8?B?Qm9iIEtlbGxlcg==?=, Nov 30, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    450
    =?Utf-8?B?Qm9iIEtlbGxlcg==?=
    Nov 30, 2005
  3. jacob navia
    Replies:
    3
    Views:
    582
    Nick Keighley
    Feb 24, 2010
  4. Keith Thompson
    Replies:
    10
    Views:
    724
    Tim Rentsch
    Mar 3, 2010
  5. kaleem
    Replies:
    8
    Views:
    887
    Tad McClellan
    Dec 14, 2006
Loading...

Share This Page