python - 使用 Python 保存时来自终端的数据会被破坏
问题描述
我正在尝试从 ubuntu 终端中的命令获取数据并在 python 中使用它。当我在 python 中打印输出时,我得到了正确的东西(部分数据):
[+] Boot and services
------------------------------------
- Service Manager [ systemd ]
- Checking UEFI boot [ DISABLED ]
- Checking presence GRUB2 [ FOUND ]
- Checking for password protection [ NONE ]
- Check running services (systemctl) [ DONE ]
Result: found 35 running services
但是当我保存它时,在变量\到文件\中将输出权发送到文本文件(在终端中使用 >)我得到了这个:
[+] [1;33mBoot and services[0m
------------------------------------
[2C- Service Manager[42C [ [1;32msystemd[0m ]
[2C- Checking UEFI boot[39C [ [1;37mDISABLED[0m ]
[2C- Checking presence GRUB2[34C [ [1;32mFOUND[0m ]
[4C- Checking for password protection[23C [ [1;31mNONE[0m ]
[2C- Check running services (systemctl)[23C [ [1;32mDONE[0m ]
[8CResult: found 35 running services[20C
这应该是一样的。
我正在使用的python代码:
output_lynis = subprocess.getoutput(to_execute)
print(output_lynis)
打印它是可以的,但将它保存到变量\文件会破坏它。我的问题显然是,我怎样才能正确保存它?(我在 ubuntu 中运行 lynis 并尝试保存输出)
解决方案
推荐阅读
- python - 将单个数组维度写入 Excel 工作表
- angular - Tinymce Angular 2 响应式文件管理器
- selenium - 删除“TooLongFrameException”限制 (http)
- java - 如何向具体用户发送 websocket 消息?
- ionic3 - Ionic image picker plugin, showing image not working
- sql-server - SQL 查询中的变量
- r - 更新数据框
- java - 测试API时如何避免代码重复
- c++ - 在 Linux 上构建 c++ 包时 autogen.sh 的工作是什么
- python - Python3,如果两个变量具有相同的值,那么它们是否具有相同的地址?