我正在执行从python连接到外部服务器的程序。
如果用户未通过身份验证,程序会要求输入用户名和密码。第一行后杀死子进程
下面是子程序输出的外观:
Authentication Required
Enter authorization information for "Web API"
<username_prompt_here>
<password_prompt_here>
我要杀死子“身份验证要求”在打印后对的,但问题是,我的代码工作错误 - 子是要求凭据后用户提供它,子进程被终止。
这里是我的代码:
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)
我在做什么错?
你能发布完整的代码吗?还是完成?我没有看到您提示用户输入用户名和密码的位置。 –
我没有提示 - 子程序会这样做(查看attatched输出)。 – Djent
并且您想在Authentication Required行后立即终止进程? –