简体   繁体   中英

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. So, I was trying some tools for Linux, and when I try to use some tools the STDOUT comes with:

stty: 'standard input': Inappropriate ioctl for device" message error

Question

Is possible to suppress this error message without the .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

Type: msfconsole

*wait a few seconds for load the banner

Type: banner

   =[ metasploit v6.0.15-dev                          ]
  • -- --=[ 2071 exploits - 1123 auxiliary - 352 post ]
  • -- --=[ 592 payloads - 45 encoders - 10 nops ]
  • -- --=[ 7 evasion ]

Metasploit tip: Use the edit command to open the currently active module in your editor

stty: 'standard input': Inappropriate ioctl for device

stty: 'standard input': Inappropriate ioctl for device

stty: 'standard input': Inappropriate ioctl for device

stty: 'standard input': Inappropriate ioctl for device

stty: 'standard input': Inappropriate ioctl for device

stty: 'standard input': Inappropriate ioctl for device

stty: 'standard input': Inappropriate ioctl for device

msf6>

Type:

You can add other exceptions, like you did for cls :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM