问题
基本上,我已经使用了一个模拟真实终端的Python脚本。所以,我在尝试Linux的一些工具,当我尝试使用STDOUT附带的一些工具时:
stty: 'standard input': Inappropriate ioctl for device" message error
问题
是否可以在不使用.replace()的情况下抑制此错误消息
脚本
import subprocess
import os
f = open('output.txt', 'w')
proc = subprocess.Popen('/bin/bash', stderr=subprocess.STDOUT, stdin=subprocess.PIPE, stdout=f, shell=True)
while True:
command = input('Type:')
if command == "cls":
open('output.txt', 'w').close()
os.system('cls' if os.name == 'nt' else 'clear')
else:
command = command.encode('utf-8') + b'\n'
proc.stdin.write(command)
proc.stdin.flush()
with open('output.txt', 'r+') as ff:
print(ff.read())
错误示例
$python3 script.py
类型:msfconsole
*等待几秒钟以加载横幅
类型:横幅
=[ metasploit v6.0.15-dev ]
Metasploit提示:使用edit命令在编辑器中打开当前活动的模块
stty:“标准输入”:设备的ioctl不正确
stty:“标准输入”:设备的ioctl不正确
stty:“标准输入”:设备的ioctl不正确
stty:“标准输入”:设备的ioctl不正确
stty:“标准输入”:设备的ioctl不正确
stty:“标准输入”:设备的ioctl不正确
stty:“标准输入”:设备的ioctl不正确
msf6>
类型:
您可以添加其他异常,就像对
cls
所做的那样:相关问题 更多 >
编程相关推荐