0

Currently in my work placement, I have to creat a GUI thanks to Tkinter. In this GUI I have to embed a console, this console has to be interactive that is to say stdout & stderr will display in this console and user can type up a commande.

With my first research, I think xterm can be useful, but I didn't find how we can redirect stdout & stderr to it

Thanks

  • Read again the subprocess module documentation, it explains how to redirect standard streams to a subprocess. – Serge Ballesta May 04 '16 at 11:30
  • I think `subprocess.Popen(["xterm"], stdout =PIPE, stderr=PIPE, stdin=PIPE)` is a begining, but it doesn't work. English isn't my mother tongue, and of course all of documentations are in english so I certainly miss the answer – Félix Arnoult May 04 '16 at 13:53
  • Possible duplicate of [How to embed a terminal in a Tkinter application?](http://stackoverflow.com/questions/7253448/how-to-embed-a-terminal-in-a-tkinter-application) – Terry Jan Reedy May 04 '16 at 19:21
  • Duplicate of https://stackoverflow.com/questions/7253448/how-to-embed-a-terminal-in-a-tkinter-application. Another duplicate (with answer): https://stackoverflow.com/questions/36929911/how-do-i-embed-the-console-that-my-tkinter-py-file-runs-with-into-the-gui-of. I searched `[tkinter] embed console` – Terry Jan Reedy May 04 '16 at 19:23
  • Thank you, before I wrote this post I checked on internet and found those posts, the solution which is offer make a terminal but output are not redirected http://imgur.com/HQpzEWD – Félix Arnoult May 09 '16 at 12:10

1 Answers1

0

You should start with an analysis of what you expect:

  • input from user: what do you want, how you want to process it? (is this really shell input?)
  • feed back: what do you want to display, how is it produced? (direct shell output?)

xterm is just a graphic interface around a shell. That means that is captures keyboard input coming to its window, submit it to is shell, and in turn display its shell stdout and stderr to the window, with respect to formatting code (not for from vt220 terminal + ANSI color codes). It is uncommon to use xterm in a GUI.

The shell can be any command line program that processes standard input and uses standard output and standard error streams. It is commonly /bin/sh or bin/bash but could be any program.

If you really want to do that, you could start xterm in a subprocess, with a special shell that passes all input lines to your main program for example through a Unix domain socket, and in turn echoes back what your main program sends to it.

More commonly, GUIs use an text widget to get input from the user and another or the same widget to display feedback. Until you have analyzed things at that level and designed a global architecture please do not think too much about subprocess module syntax.

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252