I'm trying to non-interactively execute a git pull
command with subprocess.Popen
. Specifically, if for some reason git asks for a password, the command should fail. But instead, it asks the password in the shell I run my python program in, and waits for my input, this not what I want.
I also need to capture the output of the command (this is why I use subprocess.Popen
). I have noted that if I use stdout = DEVNULL
then it behaves as I want, excepted I do need to pipe stdout to capture it.
Here is a simplified version of the code I use to execute the command:
from subprocess import Popen, PIPE, STDOUT, DEVNULL
process = Popen(['git', 'clone', 'https://some-url.git'], stdin = DEVNULL, stdout = PIPE)
for line in process.stdout:
print(line.decode())
process.wait()
I've also tried with stdin = None
. This parameter seems to have no effect.
I'm executing the python program in a bash console on a Debian 11 system (but I'd like a portable solution).