Is it possible to have python open a terminal and write to it?


For example, if I have this code:


Is it possible to have python output strings to that specific terminal that was just opened? Thanks!


Possibly, but it is easier to have a custom process running in the subordinate terminal. For example, given sserv.py from the <a href="http://docs.python.org/library/socketserver.html#socketserver-tcp-server-example" rel="nofollow">example server in the documentation</a> the command:

gnome-terminal -e "python ./sserv.py"

will happily chat on port 9999 with you. Given a more complex sserv.py it could do anything you want (anything terminalish, that is).


I think that <a href="http://www.noah.org/wiki/Pexpect" rel="nofollow">PExpect</a> might do this for you:


Pexpect is basically a pattern matching system. It runs programs and watches output. When output matches a given pattern Pexpect can respond as if a human were typing responses. Pexpect can be used for automation, testing, and screen scraping. Pexpect can be used for automating interactive console applications such as ssh, ftp, passwd, telnet, etc. It can also be used to control web applications via lynx, w3m, or some other text-based web browser. Pexpect is pure Python. Unlike other Expect-like modules for Python Pexpect does not require TCL or Expect nor does it require C extensions to be compiled. It should work on any platform that supports the standard Python pty module.



  • ssh/login to a buildserver on the network and logout
  • How to add hostname to known_hosts using Python?
  • New to Python Threading - It doesn't appear to make a difference
  • Parsing XML file with UTF-8 encoding and bytestring using ElemTree [duplicate]
  • DateTime parsing in PowerShell
  • How to run linqpad 2.x and 4.x side by side?
  • NodeJS using node-serialport sometimes becomes unresponsive
  • XMPPConnection Error in android
  • android.app.PendingIntent cannot be accessed ouside the package
  • Is it possible to send skype chat messages from a linux server without X?
  • Are there any side effects from calling SQLAlchemy flush() within code?
  • CORS with socket.io
  • powershell Get-Counter -ComputerName parameter on Windows 7
  • Aptana 3 remove bundle (jquery)
  • How can I run DataNucleus Bytecode Enhancer from SBT?
  • Prevent Tomcat from caching request during starup
  • How to get links to open in the native browser in iOS Meteor apps?
  • How can I replace the server in Web Component Tester
  • aapt.exe'' finished with non-zero exit value 1
  • How to install node-mysql?
  • Suppressing passwd when calling sqlplus from shell script
  • Check for zero lines output from command over SSH
  • Run multiple queries from 1 SQL file showing result in multiple tables
  • Copy to all folders batch file?
  • Access Android Market through SSH tunnel
  • How to run “Deployd” on port 80 instead of port 5000 in webserver.
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • Jenkins: How To Build multiple projects from a TFS repository?
  • How do I fake an specific browser client when using Java's Net library?
  • Is possible to count alias result on mysql
  • Volusion's generic SQL folder, functionality
  • Jquery - Jquery Wysiwyg return html as a string
  • Apache 2.4 - remove | delete | uninstall
  • Calling of Constructors in a Java
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • SQL merge duplicate rows and join values that are different
  • How do you join a server to an Active Directory (domain)?
  • coudnt use logback because of log4j
  • costura.fody for a dll that references another dll
  • Reading document lines to the user (python)