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

  • Home
  • SEARCH
  • 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 8502375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:28:01+00:00 2026-06-11T01:28:01+00:00

I have a linux application that gets an input stream from some device. That

  • 0

I have a linux application that gets an input stream from some device. That input should be directed to a shell process so that it emulates to the user a standard shell. So far, I’ve done it by creating a process that runs ‘/bin/sh’ and I redirected its input, output, and stderr as follows:

import subprocess

p = subprocess.Popen(shell=False, args=['/bin/sh'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
_make_nonblocking(p.stdout) # sets O_NONBLOCK
_make_nonblocking(p.stderr)

When I just a pass command, everything works:

p.stdin.write('pwd\n')
p.stdout.read()
'/home/dave\n'

For auto completion, I tried writing:

p.stdin.write('ls s\t')
p.stdout.read()
IOError: [Errno 11] Resource temporarily unavailable

I expect to get a list of possible completions but nothing happens until I put ‘\n’ in stdin. (Also, there was nothing waiting in stderr).

I’ve looked through the telnetd code and saw the use of pty. I tried to use pty.openpty() and set slave as stdin, but that didn’t work either. How should it be done?

UPDATE: I used the -i parameter as suggested. Now I have a problem that once I use Popen and press ENTER the python shell move to the background as follows:

>>> p = subprocess.Popen(shell=False, args=['/bin/sh', '-i'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> <ENTER>
[1]+ Stopped                ipython
$ 
  • 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-06-11T01:28:03+00:00Added an answer on June 11, 2026 at 1:28 am

    Eventually to completely solve all problems I had to do several things:

    1. configure a pty device (using pty module in python).
    2. set the appropriate flags using termios (echo, signal handling, etc).
    3. start a new session (so that signals won’t propagte the original process).
    4. open the pty device using an unbuffered file (passing 0 in bufsize).

    This is the code that works:

    def prepare():
        os.setsid() # start a new detached session
        tty.setcbreak(sys.stdin) # set standard input to cbreak mode
        old = termios.tcgetattr(sys.stdin)
        old[0] |= termios.BRKINT # transforms break to SIGINT
        old[3] &= termios.ICANON # non-canonical mode
        old[3] |= termios.ECHO | termios.ISIG # set echo and signal characters handling
        cc = old[6]
        # make input unbuffered
        cc[termios.VMIN] = 1
        cc[termios.VTIME] = 0
        termios.tcsetattr(sys.stdin, termios.TCSANOW, old)
    
    master, slave = pty.openpty()
    master = os.fdopen(master, 'rb+wb', 0) # open file in an unbuffered mode
    _make_non_blocking(master)
    
    prog = subprocess.Popen(shell=False, args=['/bin/sh', '-i'], stdin=slave, stdout=slave, stderr=subprocess.STDOUT, preexec_fn=prepare)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a LAMP (Linux/Apache/MySQL/Php) application that I should release soon. Even if I've
I have an application that is sensitive to the directory it gets invoked from
I have a C linux application (A) that spawns another process (P) when it
I have a java application that replays some PCM sound on my linux box.
I have created a java application for Debian Linux. Now I want that that
I have a bash script (supports linux/unix), that installs an application. Instead of executing
I have a wxPython application that needs to know when a certain file gets
I have created a linux service that runs as a deamon (and gets started
We have a c++ application which I recently ported from Linux/gcc to build on
I have a linux console application - a scientific simulation program that I use.

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.