Difficulties with python subprocess? (Unable to run wp-cli commands)

776 Views Asked by At

I am writing a simple Python script to help expedite bootstrapping my Wordpress installs and making use of wp-cli

I'm stuck at a point where I'm trying to call wp core download via a subprocess:

from subprocess import call
call(["wp", "core download"])

Which always returns

Error: This does not seem to be a WordPress install. Pass --path=path/to/wordpress or run wp core download.

Simply running the above from the python console nor from my script does not work.

Running the command directly in the shell works, of course.

I've also tried setting the PWD with os.chdir and also passing the explicit directory with the --path=... argument to no avail.

1

There are 1 best solutions below

0
On BEST ANSWER

Function subprocess.call takes as an argument list of parameters so in you case proper call should be:

call(["wp", "core", "download"])

Maybe for you it's better to use subprocess.Popen which takes as argument cwd even though its usage isn't as simple as just subprocess.call.

If none of this helps maybe try running just call(["pwd"]) to see if setting CWD using os.chdir works as you expect.