是否可以阻止subprocess.popen
在终端中显示提示?
尝试映射驱动器但希望读取脚本中的凭据提示,而不是将其显示到终端。我的想法是我可以根据回应执行行动。
我知道在使用基于字符串的命令时(由于显而易见的原因),shell
的使用不受欢迎,但我控制输入,因此对测试目的的风险感到满意。
我的印象是所有stdout
(互动)都会被解析为output_null
变量。相反,我仍然在终端获得提示(如下图所示)。我要么想知道流是如何工作的,要么我错过了什么。请有人开导我吗
command = "mount -t smbfs //{s}/SYSVOL {m}".format(s=server, m=temp_dir)
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output_null = p.communicate()[0]
if "Password for" in output_null:
print 'awdaa'
终端展示
Password for 192.168.1.111: