| | |
Setting a variable to the Exit Code
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2005
Posts: 6
Reputation:
Solved Threads: 0
Hello, I am new to Python and I am just starting to figure things out but this one has me stumped.
I need to capture the exit code of my processes in order to track them in a database. I have all the other components working except this. In DOS I use:
Echo %errorlevel%
then post the value of %errorlevel% to the SQL table by calling a CF page and passing the value in the URL.
Is there a way to calculate %errorlevel% with the exit code of the process in Python? I need Python to set %errorlevel% equal to the exit code. I’m pretty sure that ‘%’ is not the proper syntax in Python to designate a variable but, as I said, I’m new. Below is the Python code that I am using to open the CF page that inserts the data to SQL.
opener = urllib.FancyURLopener({})
n_url = opener.open('http://cob/gis/GISAutoProcess_Action.cfm?ProcessID=000&ErrorCode=%errorlevel%')
for line in n_url.readlines():
print line
Thanks in advance for your help.
I need to capture the exit code of my processes in order to track them in a database. I have all the other components working except this. In DOS I use:
Echo %errorlevel%
then post the value of %errorlevel% to the SQL table by calling a CF page and passing the value in the URL.
Is there a way to calculate %errorlevel% with the exit code of the process in Python? I need Python to set %errorlevel% equal to the exit code. I’m pretty sure that ‘%’ is not the proper syntax in Python to designate a variable but, as I said, I’m new. Below is the Python code that I am using to open the CF page that inserts the data to SQL.
opener = urllib.FancyURLopener({})
n_url = opener.open('http://cob/gis/GISAutoProcess_Action.cfm?ProcessID=000&ErrorCode=%errorlevel%')
for line in n_url.readlines():
print line
Thanks in advance for your help.
Hi mccarthp,
Let me see if I understand this. Windows maintains a variable called errorlevel, which contains the exit code of the most recently executed program, right? And you are trying to read that variable?
Hmm. Off the top of my head, we could try:
But I don't see the errorlevel variable in this list.
Well, I don't know how to query for non-environment variables in DOS, but here's a quick workaround:
The value of errorlevel should be inside text, along with some whitespace, but you can take care of that yourself, then insert the code into your URL string.
Let me see if I understand this. Windows maintains a variable called errorlevel, which contains the exit code of the most recently executed program, right? And you are trying to read that variable?
Hmm. Off the top of my head, we could try:
Python Syntax (Toggle Plain Text)
import os keys = os.environ.keys() keys.sort() for item in keys: print item, ":", os.environ[item]
Well, I don't know how to query for non-environment variables in DOS, but here's a quick workaround:
Python Syntax (Toggle Plain Text)
import os f = os.popen("echo %errorlevel%", "r") text = f.read()
Vi veri veniversum vivus vici
![]() |
Similar Threads
- exit code error (C++)
- Exit code and prompting message box (ASP.NET)
- How to capture STDOUT and the exit code (Perl)
- Exit Codes (Python)
- How to open IE and pass an exit code in the URL (Python)
Other Threads in the Python Forum
- Previous Thread: Handle unicode characters
- Next Thread: Cryptography Fun
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied apache application argv beginner book change code color converter dictionary dynamic edit editing enter examples excel file filename float format ftp function gui homework import inches input java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysql newb number numbers numeric output parameters parsing path phonebook port prime program programming projects py2exe pygame pyopengl pyqt python random recursion recursive redirect remote reverse scrolledtext server session simple smtp software sprite ssh statictext string strings syntax table tennis terminal text thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable windows wordgame wxpython





