[英]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.