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 8128525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:55:03+00:00 2026-06-06T07:55:03+00:00

In Python code, I frequently send commands to the shell and read the response

  • 0

In Python code, I frequently send commands to the shell and read the response using

import subprocess as S
x = subprocess.Popen('<command>', shell=True, stdout=S.PIPE)
x.stdout.read()

, where <command> is the shell command in question. However, I find that when this instruction is issued in a subprocess, for a command stty size, for example, the shell responds with

stty: stdin isn't a terminal

and my instruction returns an empty string. Following the Python docs at http://docs.python.org/library/subprocess#popen-objects , I have also tried replacing stdout.read() with communicate():

x = subprocess.Popen('<command>', shell=True, stdin=S.PIP, stdout=S.PIPE)
x.stdout.read()

but the shell still responds the same way.

My question: How can I make Python treat standard input as a terminal?

  • 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-06T07:55:05+00:00Added an answer on June 6, 2026 at 7:55 am

    It’s not that Python isn’t treating stdin like a terminal; if stdin is a terminal, Python is likely treating it as such. But the subprocess’s stdin may not be. In the second case, it definitely isn’t a terminal, since you are explicitly using a pipe instead.

    You probably won’t be able to make stty treat a pipe as a terminal, short of changing the way it works. But that probably isn’t what you want to do, anyway.

    Your first example, though, should work if Python’s own stdin is a tty, since stty should inherit that from the shell.

    Perhaps I’m unclear on what you meant by “when this instruction is issued in a subprocess”. Technically, everything on a Un*x system except for init/launchd is a subprocess.

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

Sidebar

Related Questions

I have some python code using shutil.copyfile: import os import shutil src='C:\Documents and Settings\user\Desktop\FilesPy'
I code in Python a lot, and I frequently create classes. Now, I'm not
Here is some sample Python code: import re some_regex = re.compile(r\s+1\s+) result = some_regex.search(
I've got Python code with a preamble containing the line: from numpy import array,arccosh,random_integers
My python code spawns the child process, and it prints out messages both stdout
When writing Python code using compiled extensions (the OpenCV Python bindings, for example), PyCharm
I frequently see python code similar to for line in open(filename): do_something(line) When does
I'd like to create python command line code that is able to print directory
I am looking to create a sin curve using python. I want a code
Consider the following Python code: In [1]: import numpy as np In [2]: import

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.