I am executing program which connects to external server from python.
If user is not authenticated, the program asks for username and password.
Here is how subprogram output looks:
Authentication Required
Enter authorization information for "Web API"
<username_prompt_here>
<password_prompt_here>
I want to kill subprocess right after 'Authentication Required' is printed, but the problem is, that my code works wrong - subprocess is asking for credentials and after user provides it, the subprocess is killed.
Here is my code:
with subprocess.Popen(self.command, stdout=subprocess.PIPE, shell=True, bufsize=1, universal_newlines=True) as process:
for line in process.stdout:
if 'Authentication Required' in line:
print('No authentication')
process.kill()
print(line)
What am I doing wrong?