I'm trying to make a Terminal Emulator and for that I need to handle stdin/stdout/stder
to redirect them to a GUI
I already managed to handle stdout and stderr
, the problem is for stdin
.
I would like to have a function that is called every time stdin
is read, so I could request input to the user.
I use
subprocess.Popen("command", shell="True")
I tried using temp file and editing read
, readline
and readlines
of the files but the problem is that if I understood correctly (from the source) subprocess.Popen
takes the file and reopen it to use it.
I also tried creating custom file like objects but as I said before subprocess.Popen
takes the file and try to reopen it but as my object is a fake file it does not work
How could I create a stdinRedirector?
Something like that
class StdinRediector():
def read():
input = gui.ask_input()
return input
subprocess.Popen(
"command",
shell="True",
stdin=StdinRediector,
)
I don't ask for stdout and stderr
as there is already answers here:
- Display realtime output of a subprocess in a tkinter widget
- live output from subprocess command
- How to use a custom file-like object as subprocess stdout/stderr?
but these don't talk about stdin
which is my problem.
THIS IS NOT DUPLICATE