如何抑制“stty:“标准输入”:设备的ioctl不正确”错误

2024-06-01 20:18:14 发布

您现在位置:Python中文网/ 问答频道 /正文

问题

基本上,我已经使用了一个模拟真实终端的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                          ]
  • ---->=[2071次漏洞利用-1123次辅助-352次发布]
  • ---->=[592个有效载荷-45个编码器-10个NOP]
  • -----=[7回避]

Metasploit提示:使用edit命令在编辑器中打开当前活动的模块

stty:“标准输入”:设备的ioctl不正确

stty:“标准输入”:设备的ioctl不正确

stty:“标准输入”:设备的ioctl不正确

stty:“标准输入”:设备的ioctl不正确

stty:“标准输入”:设备的ioctl不正确

stty:“标准输入”:设备的ioctl不正确

stty:“标准输入”:设备的ioctl不正确

msf6>

类型:


Tags: 工具txt脚本类型output标准osstdin