your command should use
shell=True
since it's using 2 commands chained by an exit condition test
cwd=your_directory
- status check
like this:
from subprocess import call
status = call("mvn clean && mvn compile",cwd="/users/foo/xxx",shell=True)
Personally I tend to avoid depending on shell=True
. In those cases I tend to decompose both commands and put arguments directly as argument list so if some nasty whitespace slips in it is quoted automatically:
if call(["mvn","clean"],cwd="/users/foo/xxx") == 0:
status = call(["mvn","compile"],cwd="/users/foo/xxx")
Note that if you want to get hold of the commands output from the python side (without redirecting to a file, which is dirty), you'll need Popen
with stdout=PIPE
instead of call