[英]How to supress the “stty: 'standard input': Inappropriate ioctl for device” error
Problem问题
Basically I've have working with a Python script that emulate a real terminal.基本上我已经使用了模拟真实终端的 Python 脚本。 So, I was trying some tools for Linux, and when I try to use some tools the STDOUT comes with:
所以,我正在尝试一些用于 Linux 的工具,当我尝试使用一些工具时,STDOUT 附带:
stty: 'standard input': Inappropriate ioctl for device" message error
stty:“标准输入”:设备的 ioctl 不合适”消息错误
Question问题
Is possible to suppress this error message without the .replace() ?是否可以在没有.replace()的情况下抑制此错误消息?
Script脚本
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())
Error example错误示例
$ python3 script.py $ python3脚本.py
Type: msfconsole类型:msfconsole
*wait a few seconds for load the banner *等待几秒钟以加载横幅
Type: banner类型:横幅
=[ metasploit v6.0.15-dev ]
Metasploit tip: Use the edit command to open the currently active module in your editor Metasploit 提示:使用 edit 命令在编辑器中打开当前活动的模块
stty: 'standard input': Inappropriate ioctl for device stty:“标准输入”:设备的 ioctl 不合适
stty: 'standard input': Inappropriate ioctl for device stty:“标准输入”:设备的 ioctl 不合适
stty: 'standard input': Inappropriate ioctl for device stty:“标准输入”:设备的 ioctl 不合适
stty: 'standard input': Inappropriate ioctl for device stty:“标准输入”:设备的 ioctl 不合适
stty: 'standard input': Inappropriate ioctl for device stty:“标准输入”:设备的 ioctl 不合适
stty: 'standard input': Inappropriate ioctl for device stty:“标准输入”:设备的 ioctl 不合适
stty: 'standard input': Inappropriate ioctl for device stty:“标准输入”:设备的 ioctl 不合适
msf6> msf6>
Type:类型:
You can add other exceptions, like you did for cls
:您可以添加其他例外,就像您为
cls
所做的那样:
elif command == "stty" or command == "...":
os.system(command)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.