import subprocess
cmd = subprocess.Popen('tracert -d 192.168.1.125', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
for info in iter(cmd.stdout.readline, 'b'):
if info == b'':
pass
else:
print(str(info, encoding='gbk'))
python代码如上,保存在test.py中,在Linux中执行python test.py 一直没有反应,直接ctrl后提示错误:
^CTraceback (most recent call last):
File "test.py", line 4, in <module>
for info in iter(cmd.stdout.readline, 'b'):
KeyboardInterrupt
请问是什么原因,如何chu'li