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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:36:08+00:00 2026-06-02T05:36:08+00:00

We have: A Python based server (A) A running command-line application (on the same

  • 0

We have:

  • A Python based server (A)
  • A running command-line application (on the same Linux machine) which is able to read stdin, computes something and provides the output into stdout (B)

What is the best (most elegant) way how to send an input from (A) to stdin of (B), and wait for an answer from (B), i.e read its stdout?

  • 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-02T05:36:09+00:00Added an answer on June 2, 2026 at 5:36 am

    As @Deestan pointed subprocess,module, is an elegant and proven one. We use subprocess a lot when we have to run commands from python.

    Ours mostly involves running a command, mostly in-house built, and capturing its output. Our wrapper to run such commands looks thus.

    import subprocess
    def _run_command( _args, input=[],withShell=False):
        """
        Pass args as array, like ['echo', 'hello']
        Waits for completion and returns
        tuple (returncode, stdout, stderr)
        """
        p = subprocess.Popen(_args, shell = withShell,
                             stdin=subprocess.PIPE, stdout=subprocess.PIPE)
        [p.stdin.write(v) for v in input]
        stdout, stderr = p.communicate()
        return p.returncode, stdout, stderr
    
    _,op,er = _run_command(['cat'],["this","is","for","testing"])
    value="".join(op)
    print value
    
    _,op,er = _run_command(['ls',"/tmp"])
    value="".join(op)
    print value
    

    If your input to B is minimal then subprocess is a yes.

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

Sidebar

Related Questions

I have a program with a Mono-based C# client and a Python server, which
For our company I'd like to have a Python based IRC bot which checks
I have a simple python server script which forks off multiple instances (say N)
I have a simple python telnet based chat server that lacks the functionality for
I have a Windows Server 2008 R2 (64bits) machine on which I wanted to
I have an audio broadcasting server written in Python and based on Twisted. It
I use python based as well as rails applications on ubuntu linux. We have
I develop a Python-based drawing program, Whyteboard . I have tools that the user
I have python script which downloads N number of images from website. I run
I have a requirement to integrate a web server into an embedded device running

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.