Mailing List Archive

Question - Returning exit codes
Hello All
I'm calling my python program from a perl script using the system
command. I was wondering what would be the best way to return exit
codes from my python script so that they can be intercepted in the perl
program.

thanks
Sunit


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
Question - Returning exit codes [ In reply to ]
On Thu, Jun 24, 1999 at 01:27:07PM +0000, sjoshi@ingr.com wrote:
> Hello All
> I'm calling my python program from a perl script using the system
> command. I was wondering what would be the best way to return exit
> codes from my python script so that they can be intercepted in the perl
> program.
>

#!/usr/bin/python
"""example on using exit codes"""

import sys

def exit_with_code():
number = input("What exit code do you want? ")
sys.exit(number)

if __name__ == '__main__':
exit_with_code()



or easier:

sys.exit(1)

groeten,
Gerrit.

--
The Dutch Linuxgames homepage: http://linuxgames.nl.linux.org
Personal homepage: http://www.nl.linux.org/~gerrit/

Discoverb is a python program in Dutch and English which tests the words you
learned by asking it. Homepage: http://www.nl.linux.org/~gerrit/discoverb/
Question - Returning exit codes [ In reply to ]
sjoshi@ingr.com wrote:
>
> Hello All
> I'm calling my python program from a perl script using the system
> command. I was wondering what would be the best way to return exit
> codes from my python script so that they can be intercepted in the perl
> program.
>
> thanks
> Sunit
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.

import sys
sys.exit(1) # replace 1 with your exit code of choice

=============================================================================
michaelMuller = proteus@cloud9.net | http://www.cloud9.net/~proteus
-----------------------------------------------------------------------------
Government, like dress, is the badge of lost innocence; the palaces of
kings
are built on the ruins of the bowers of paradise. - Thomas Paine
=============================================================================
Question - Returning exit codes [ In reply to ]
sjoshi@ingr.com wrote:
: Hello All
: I'm calling my python program from a perl script using the system
: command. I was wondering what would be the best way to return exit
: codes from my python script so that they can be intercepted in the perl
: program.

: thanks
: Sunit

Either call sys.exit(rc) or raise the SystemExit exception with the
numeric return code.

If the exception data is not an integer, the string representation is
printed to stderr and the return code is 1. Otherwise, nothing is
printed (no traceback) and integer is the return code.

Note: the sys.exit() function raises the SystemExit exception.

-Arcege