subprocess troubles

T

Tomas Pelka

Hey all,

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)
(stdoutdata, stderrdata) = p1.communicate()

print p1.returncode
print "%s -- %s" % (stdoutdata, stderrdata)
--------------------------------------------------

But return code is always 1 and command do not return any result/error
(stdoutdata, stderrdata are None). 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?

Thanks
Cheers
 
N

Nobody

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top