subprocess troubles

Nobody nobody at nowhere.com
Fri Jan 22 11:30:54 EST 2010


On Thu, 21 Jan 2010 11:25:08 +0100, Tomas Pelka wrote:

> have a problem with following piece of code:
> 
> --------------------------------------------------
> import subprocess
> 
> paattern = "python"
> cmd = "/usr/bin/locate"
> arg1 = " -i"
> arg2 = " -d /var/www/books/mlocate.db"
> arg3 = str(" " + pattern)
> p1 = subprocess.Popen([cmd, arg1, arg2, arg3], shell=False,
> stdout=subprocess.PIPE, stderr=subprocess.PIPE)

You probably want:

arg1 = "-i"	# no leading space
arg2 = "-d"	# no leading space
arg3 = "/var/www/books/mlocate.db"
arg4 = pattern
p1 = subprocess.Popen([cmd, arg1, arg2, arg3, arg4], ...


> If I run this command 
> (/usr/bin/locate -i -d /var/www/books/mlocate.db python) from standard 
> shell everything goes fine.
> 
> Could you please give me an advice what I'm doing wrong?

You're putting spaces where they aren't wanted.





More information about the Python-list mailing list