[英]How to supress the “stty: 'standard input': Inappropriate ioctl for device” error
问题
基本上我已经使用了模拟真实终端的 Python 脚本。 所以,我正在尝试一些用于 Linux 的工具,当我尝试使用一些工具时,STDOUT 附带:
stty:“标准输入”:设备的 ioctl 不合适”消息错误
问题
是否可以在没有.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脚本.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
所做的那样:
elif command == "stty" or command == "...":
os.system(command)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.