python - 如何将终端的输出写入具有格式的文件?
问题描述
我想将脚本的结果保存到文件中。脚本示例:
import os
def scan_ip():
ip2 = raw_input('Enter ip of target: ')
target = 'nmap -sP {}'.format(ip2)
os.system(target + > '123.txt')
解决方案
with open('123.txt', 'w') as my_file:
my_file.write(target)
推荐阅读
- android - ReorderableListView : 多个小部件使用相同的 GlobalKey
- python - 在 Selenium 中获取文件选择器对话框的 ID 或其他句柄
- wolkenkit - Wolkenkit 服务的可扩展性
- python - 如何将我的 Rest Api 服务器与我的 Web Socket 服务器通信
- visual-studio-2017 - 如何将 QT5 中的 *.dll 添加/链接到 Visual Studio 2017
- c# - 从数组属性中分配随机文本框
- cimg - CIMG 的外部库错误
- javascript - 如何在nodejs中从mysql显示数据到html div?
- angular - 如何在 Angular 中使用 MatOptgroup 来实现自动完成?
- sql - 如何在不将 TABLE1 中的列设置为特定的单个选择语句的情况下使用 TABLE2 中的值更新 TABLE1?