Subprocess Call works on Windows, but not Ubuntu

Brett Bowman bnbowman at gmail.com
Tue Nov 23 15:31:25 EST 2010


Ah, that fixed it.  Thank you.

On Tue, Nov 23, 2010 at 11:37 AM, Chris Rebert <clp2 at rebertia.com> wrote:

> On Tue, Nov 23, 2010 at 11:28 AM, Brett Bowman <bnbowman at gmail.com> wrote:
> > I ran into an interesting problem trying to spawn a subprocess, so I
> thought
> > I'd ask if the experts could explain it to me.  I'm spawning a subprocess
> to
> > run "pdf2txt.py", which is a tool that is distributed with PDFminer to do
> > moderately advanced text-dumps of PDFs.  Yet when I run the same code on
> my
> > two dev machines - one Win XP, the other Ubuntu 10.04 or 10.10 - it only
> > works on the former and not the later. And its not terribly complicated
> > code.
> > # Code Start
> > sp_line = 'python pdf2txt.py -p 1 -o %s "%s"' % ('temp.out',
> pdf_filename)
> > print sp_line
> > sp = subprocess.Popen(sp_line)
> <snip>
> > python pdf2txt.py -p 1 -o temp.out "Aarts et al (2009).pdf"
> > That command works on both systems when copied directly to the
> command-line,
> > and the python script it is a part of works on the Windows machine, but I
> > can't the script to work on Ubuntu for the life of me.  What am I
> missing?
>
> Quoting the docs (for the Nth time; emphasis added):
> """
> On Unix, with shell=False (default): args should normally be a
> sequence. ***If a string is specified for args***, it will be used as
> the name or path of the program to execute; ***this will only work if
> the program is being given no arguments.***
> """ http://docs.python.org/library/subprocess.html#subprocess.Popen
>
> Fixed version:
> sp_args = ['python', 'pdf2txt.py', '-p', '1', '-o', 'temp.out',
> pdf_filename]
> sp = subprocess.Popen(sp_args)
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101123/02ae9a00/attachment.html>


More information about the Python-list mailing list