I'm trying to figure out how to handle a bash logical operator ('&&') in a Python subprocess.
The command, obviously works as expected on the terminal:
git fetch && git diff --name-only ..origin/master
When I try this, I get an error saying C is an unknown switch:
subprocess.Popen(['git', '-C', repo_path, 'fetch', '&&', 'git', '-C', repo_path, 'diff', '--name-only', '..origin/master'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
I'm sure I am missing something silly, but I can't find anything regarding how to handle the '&&' operator.
Thanks for your help
Edit
Thanks @heitor for pointing in the good direction.
Basically, Popen doesn't use shell operator by default, shell=True
need to be added.
I'm still getting an git error, which might be related to the -C option. I'll work on this error tomorrow. Cheers.