Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7686565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:30:34+00:00 2026-05-31T19:30:34+00:00

I am writing a Python program which runs a virtual terminal. Currently I am

  • 0

I am writing a Python program which runs a virtual terminal. Currently I am launching it like so:

import pexpect, thread

def create_input(child, scrollers, textlength=80, height=12):
    while 1:
        newtext = child.readline()
        print newtext

child = pexpect.spawn("bash", timeout=30000)

thread.start_new_thread(create_input,(child))

This works, and I can send commands to it via child.send(command). However, I only get entire lines as output. This means that if I launch something like Nano or Links, I don’t receive any output until the process has completed. I also can’t see what I’m typing until I press enter. Is there any way to read the individual characters as bash outputs them?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:30:35+00:00Added an answer on May 31, 2026 at 7:30 pm

    The problem is lies in something else. If you open an interactive shell normally a terminal window is opened that runs bash, sh, csh or whatever. See the word terminal!

    In the old days, we connected a terminal to a serial port (telnet does the same but over ip), again the word terminal.

    Even a dumb terminal respond to ESC codes, to report its type and to set the cursor position, colors, clear screen etc.

    So you are starting a subprocess with interactive output, but there is no way in telling that shell and subprocesses are to a terminal in this setup other than with bash startup parameters if there are any.

    I suggest you enable telnetd but only on localhost (127.0.0.1)
    Within your program, make a socket and connect to localhost:telnet and look up how to emulate a proper terminal. If a program is in line mode you are fine but if you go to full screen editing, somewhere you will need an array of 80×24 or 132×24 or whatever size you want to store its characters, color. You also need to be able to shift lines up in that array.

    I have not looked but I cannot imagine there is no telnet client example in python, and a terminal emu must be there too!

    Another great thing is that telnet sessions clean up if the the ip connection is lost, eliminating ghost processes.

    Martijn

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a program in Python, and I would like to determine the
Is there any way of writing pexpect like small program which can launch a
In the python program I'm writing, I've got a thread which iterates over a
I'm writing a Python program for Linux and the program basically uses the terminal
I'm writing a Python program that logs terminal interaction (similar to the script program),
I am currently writing a non-web program using mostly python and have gotten to
So, I've got a multithreaded python program, which is currently suffering from deadlock. I
I'm writing a program in python 3 which needs encryption functions (at least aes
I currently have an implementation using the pexpect python module, which interacts with Juniper,
I'm currently writing a program in python with a gui using wxpython. The program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.