473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Can I get the exit code "n" passed to sys.exit(n) ?

Hello everybody,

In the following code of the finish() function, is there any way to
get the exit code passed to sys.exit() ?

def finish() :
RETURN_CODE_FROM_SYS_EXIT = ???? # how can I get it ?
if RETURN_CODE_FROM_SYS_EXIT = 0 :
# process ended OK
else :
# process ended with some error
# execute something

atexit.register(finish)

# this is my main program....

ERR_CODE=3
sys.exit(ERR_CODE)
Regards,

Yujo

Apr 10 '07 #1
2 1594
On Apr 10, 1:15 pm, "Yujo" <yujorodrig...@gmail.comwrote:
Hello everybody,

In the following code of the finish() function, is there any way to
get the exit code passed to sys.exit() ?

def finish() :
RETURN_CODE_FROM_SYS_EXIT = ???? # how can I get it ?
if RETURN_CODE_FROM_SYS_EXIT = 0 :
# process ended OK
else :
# process ended with some error
# execute something

atexit.register(finish)

# this is my main program....

ERR_CODE=3
sys.exit(ERR_CODE)

Regards,

Yujo
I'm not sure if this will help or not, but this article is pretty
enlightening and is written by a well-known Pythonista:

http://www.artima.com/weblogs/viewpost.jsp?thread=4829

Here is another older post with helpful information:
http://www.daniweb.com/techtalkforums/thread31226.html

And here's a hack that might work: http://www.daniweb.com/techtalkforums/thread31166.html

Mike

Apr 10 '07 #2
En Tue, 10 Apr 2007 15:15:57 -0300, Yujo <yu***********@gmail.com>
escribió:
In the following code of the finish() function, is there any way to
get the exit code passed to sys.exit() ?

def finish() :
RETURN_CODE_FROM_SYS_EXIT = ???? # how can I get it ?
if RETURN_CODE_FROM_SYS_EXIT = 0 :
# process ended OK
else :
# process ended with some error
# execute something

atexit.register(finish)

# this is my main program....

ERR_CODE=3
sys.exit(ERR_CODE)
Uhm, I think you can't, unfortunately (at least on 2.4; I don't have the
2.5 sources at hand).
But you can instead wrap your main function with a try/except SystemExit:

def main():
return 3

try:
sys.exit(main())
except SystemExit, exitcode:
finish(exitcode)

--
Gabriel Genellina

Apr 10 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Phill Long | last post by:
this is the the code, now here is the final result.... I get one combo box and one tex box come up, but they are empty... DAMN!!! Any ideas on what Im doing wrong please.. Thanks Again <?php...
3
by: Graham | last post by:
On page 89 of Stroustrup's book "The C++ Programming Language" 3rd Ed. He says that multidimensional arrays are best avoided outside low-level code. What precisely does he mean by low-level...
5
by: apple | last post by:
UDBV8 fp 6a - AIX 5.1 We have scheduled cron jobs to do backups. Periodically and starting to occur more frequently, a backup fails with this error: SQL2072N Unable to bind the shared library...
6
by: Wito | last post by:
hi, I want to backup database (db2, aix 5.1) using script. When I exec script logging to user db2inst1 then is everything ok, but from cron, I get these error: SQL10007N Message "-1390" could...
6
by: Rob Meade | last post by:
Hi all, Ok - I've used the word gramatically - which I'm sure is incorect, however I mean when VS2005 lists "warnings" like this one: Warning 1 Variable 'Command' is used before it has been...
2
by: MadMikey | last post by:
Can I change the order that controls are defined, or built, in the "Windows Form Designer generated code" section? I'm using VB.NET 2003. I have a custom control, that due to licensing...
1
by: Mitan | last post by:
Hello, I'm a beginner with what appears to be a simple question for which I haven't been able to get an answer. Can someone explain what "implementation code" is in relation to VB.NET? I want to be...
3
by: nan | last post by:
Hi All, I am trying to connect the Database which is installed in AS400 using DB2 Client Version 8 in Windows box. First i created the Catalog, then when i selected the connection type...
5
by: Smithers | last post by:
I'm writing a code library that needs to be reused between a Windows Forms application and and an ASP.NET Web application. The library needs to do a couple of things differently depending on the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.