【问题标题】:How to supress the "stty: 'standard input': Inappropriate ioctl for device" error如何抑制“stty:'标准输入':设备的 ioctl 不合适”错误
【发布时间】:2021-05-11 10:13:28
【问题描述】:

问题

基本上,我使用过一个模拟真实终端的 Python 脚本。所以,我尝试了一些适用于 Linux 的工具,当我尝试使用 STDOUT 附带的一些工具时:

stty: 'standard input': Inappropriate ioctl for device" 消息错误

问题

是否可以在没有 .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 个 nops ]​​i>
  • -- --=[ 7 回避]

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

stty: '标准输入': 设备的 ioctl 不合适

stty: '标准输入': 设备的 ioctl 不合适

stty: '标准输入': 设备的 ioctl 不合适

stty: '标准输入': 设备的 ioctl 不合适

stty: '标准输入': 设备的 ioctl 不合适

stty: '标准输入': 设备的 ioctl 不合适

stty: '标准输入': 设备的 ioctl 不合适

msf6>

类型:

【问题讨论】:

  • accepted answer here 能解决您的问题吗?
  • 那个问题/答案不相关。
  • @ThomasDickey - 怎么会这样?
  • 对我来说,“无效的 IOCTL”很明显与 stdout=f, 相关,使用管道作为答案建议将取消。

标签: python linux subprocess


【解决方案1】:

您可以添加其他例外,就像您为 cls 所做的那样:

    elif command == "stty" or command == "...":
        os.system(command)

【讨论】:

    猜你喜欢
    • 2011-05-01
    • 2018-12-18
    • 1970-01-01
    • 2021-12-23
    • 2014-08-28
    • 2022-06-27
    • 2010-12-08
    • 1970-01-01
    • 2014-09-17
    相关资源
    最近更新 更多