subprocess chokes on spaces in path
Thorsten Kampe
thorsten at thorstenkampe.de
Tue Nov 6 07:49:37 EST 2007
* BartlebyScrivener (Tue, 06 Nov 2007 20:32:33 -0000)
> Using bash on Debian Etch.
>
> If word_doc = sys.argv[1] and it's a file name like My\ Word.doc this
> function reads My and Word as two separate files unless the second
> '%s' is quoted. Took me a lot of trial and error to discover. Is this
> the most elegant way to do it? I was using popen originally, then saw
> some threads suggesting subprocess cured the spaces in path problem.
>
> def get_MSWordDoc_text(word_doc):
> """Harvests text from an MSWord doc using antiword."""
> antiword = "/usr/bin/antiword"
>
> # Note the extra single quotes around the second '%s'
> # without these quotes, bash chokes on paths with spaces in them
> # says can't open My ; can't open Word
If bash has problems with spaces then the obvious thing to do is not
to use bash, right?!
Thorsten
More information about the Python-list
mailing list