大家好,我正在学习python脚本,现在被困住了(使用wxpython for GUI)我的问题是,我想运行build.system,但是该build.system在执行开始后要求输入系统密码,我尝试使用pexpect,但不能使用“ sudo”。由于某种原因我不能使用sudo我也尝试过subprocess.call("echo ******* | sudo -S ./build.system %s" % (str(mode)))使用Pexpect:child = pexpect.spawn("./build.system %s" % (str(mode)))child.interact()child.expect("[sudo] password for system:")child.sendline("********")我也曾尝试过linux命令。我得到的输出:INFO: building for boardINFO: keeping existing sandbox /home/system/sandbox[sudo] password for system: 预期是:INFO: building for Stretch boardINFO: keeping existing sandbox /home/qvisdvr/sandbox[sudo] password for qvisdvr:********install alarms/alarms.hinstall alarms/alarms_int.hinstall ccm/ccm.hinstall common/defines.h[contd]寻求好的建议,在此先感谢,
1 回答

qq_笑_17
TA贡献1818条经验 获得超7个赞
try:
proc = subprocess.Popen(["./build.system %s " % (str(mode))], shell=True)
proc.stdin.write("******")
proc.stdin.flush()
except AttributeError:
pass
这对我有用。
添加回答
举报
0/150
提交
取消