【发布时间】:2021-02-28 11:07:20
【问题描述】:
如何使用 Python 将命令提示符的输出转换为文本文件
import os
with open ('ip-source.txt') as file:
test = file.read()
test = test.splitlines()
for ip in test:
os.system('ping -n 20 {}'.format(ip))
#check packet loss in 20s
#want convert into text file
【问题讨论】:
-
它无法工作,无法从 cmd 获取输出。但可以处理简单的代码
-
你可以在简单的代码上做到这一点,但在更大的代码中你应该使用logging模块。
标签: python cmd command-prompt ping python-3.8