On 17/11/2010 01:37, Brett Bowman wrote:
I'm spawning a subprocess to fix some formating errors with a library of
PDFs with pdftk:
     try:
         sp = subprocess.Popen('pdftk.exe "%s" output %s' % (pdfFile,
outputFile))
         sp.wait()
         del sp
     except Exception, e:
         return "Unable to open file: %s with error: %s" % (pdfFile, str(e))

And then I test the result:
     try:
         pdf_handle = open(outputFile, "rb")
         pdf_pypdf = PdfFileReader(pdf_handle)
         del pdf_pypdf
         del pdf_handle
     except Exception, e:
         return "Unable to open file: %s with error: %s" % (outputFile,
str(e))

Both of which appear to work.  But when I try to delete the original
pdfFile, I get an error message saying that the file is still in use.

if I use:
     sp = subprocess.Popen('rm "%s"' % pdfFile)
     sp.wait()
I get the message - the standard error message from rm

and if I use:
     cwd = os.getcwd()
     os.remove(cwd + "\\" + pdfFile)
I get "WindowsError: [Error 32]"  saying much the same thing.

What am I missing?  Any suggestions would be appreciated.

Details:
Python 2.6
Windows XP

Try Process Explorer, available from Microsoft at:

    http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx

and use Find. That will tell you what has it open.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to