【发布时间】:2019-10-07 00:50:39
【问题描述】:
我正在尝试编写一个使用 os 命令(linux)的脚本并将它们保存在文本文件中。但是当我尝试运行这段代码时,os 命令的输出并没有保存在文本文件中。
#!/usr/bin/python
import sys
import os
target = raw_input('Enter the website : ')
ping_it = os.system('ping ' + target)
string_it = str(ping_it)
with open("Output.txt", "w+") as fo:
fo.write(string_it)
fo.close()
在我检查 txt 文件时运行脚本后,我得到的唯一结果是 Output.txt 中的没有 2。
【问题讨论】:
标签: python file operating-system system