[Errno 9] Bad File Descriptor on Windows 2003 Server & Py 2.4.1

rbt rbt at athop1.ath.vt.edu
Tue May 3 13:02:17 EDT 2005


vincent wehren wrote:
> "rbt" <rbt at athop1.ath.vt.edu> schrieb im Newsbeitrag 
> news:d57sj2$amj$1 at solaris.cc.vt.edu...
> | The below script produces a '[Errno 9] Bad File Descriptor' when
> | executed. If I remove the try: except: statements, the script stops when
> | the error occurs.
> |
> | The purpose of the script is to monitor the size of the three main logs
> | on a Windows 2003 server and send and email should any of the logs get
> | shorter. It works fine... just don't know *why* it produces the '[Errno
> | 9] Bad File Descriptor' error.
> |
> | I'm running Python 2.4.1 on Windows 2003 SP1 Server with no funky win32
> | extensions ;)
> |
> | logs = ['AppEvent.Evt', 'SecEvent.Evt', 'SysEvent.Evt']
> |
> | app_size = 0
> | sec_size = 0
> | sys_size = 0
> |
> | def send_email(LogName, old_size, new_size):
> |     f = "Somebody<XXXXXXXXX at vt.edu>"
> |     t = "Somebody_Else at vt.edu"
> |
> |     msg = MIMEText("""old_size = %d, new_size = %d""" %(old_size,
> | new_size))
> |
> |     msg["Subject"] = "%s Log Just Got Shorter" %LogName
> |     msg["Message-id"] = email.Utils.make_msgid()
> |     msg["From"] = f
> |     msg["To"] = t
> |
> |     h = "smtp.vt.edu"
> |     s = smtplib.SMTP(h)
> |     s.sendmail(f, t, msg.as_string())
> |     s.quit()
> |
> | while 1:
> |
> |     for log in logs:
> |
> |         try:
> |
> |             a = os.stat('C:\WINDOWS\System32\config\%s' %log)
> 
> Without looking at the rest of script:
> 
> Try using either escaped backslashes as in:
> 
> a = os.stat('C:\\WINDOWS\\System32\\config\\%s' %log)
> 
> or a raw string (as long as it doesn't end with a single backslash) as in:
> 
> a = os.stat(r'C:\WINDOWS\System32\config\%s' %log)
> 
> or simply use forward slashes as in:
> 
> a = os.stat('C:/WINDOWS/System32/config/%s' %log)

Thanks, that worked.



More information about the Python-list mailing list