我想通过python把shell命令的输出保存到一个文本文件中。这是我实际的、相当基本的python代码。
Edit 这是最后的脚本,感谢您的帮助 :)
import subprocess
ip_adress_4 = 0
pr = open("pointer_record.txt", "w")
while (ip_adress_4 < 255):
ip_adress_4 = ip_adress_4 + 1
ip_adress = '82.198.205.%d' % (ip_adress_4,)
subprocess.Popen("host %s" % ip_adress, stdout=pr, shell=True)