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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:19:13+00:00 2026-05-30T18:19:13+00:00

I read every thread I found on StackOverflow on invoking shell commands from Python

  • 0

I read every thread I found on StackOverflow on invoking shell commands from Python using subprocess, but I couldn’t find an answer that applies to my situation below:

I would like to do the following from Python:

  1. Run shell command command_1. Collect the output in variable result_1

  2. Shell pipe result_1 into command_2 and collect the output on result_2. In other words, run command_1 | command_2 using the result that I obtained when running command_1 in the step before

  3. Do the same piping result_1 into a third command command_3 and collecting the result in result_3.

So far I have tried:

p = subprocess.Popen(command_1, stdout=subprocess.PIPE, shell=True)

result_1 = p.stdout.read();

p = subprocess.Popen("echo " + result_1 + ' | ' + 
command_2, stdout=subprocess.PIPE, shell=True)

result_2 = p.stdout.read();

the reason seems to be that "echo " + result_1 does not simulate the process of obtaining the output of a command for piping.

Is this at all possible using subprocess? If so, how?

  • 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-30T18:19:14+00:00Added an answer on May 30, 2026 at 6:19 pm

    You can do:

    pipe = Popen(command_2, shell=True, stdin=PIPE, stdout=PIPE)
    pipe.stdin.write(result_1)
    pipe.communicate()
    

    instead of the line with the pipe.

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

Sidebar

Related Questions

actually i have found some thread that asking question like mine. but every solution
I've read every Haskell deploy thread I could find here and several on the
I read some questions here but couldn't really find the specific problem I'am faced
Ever wonder what wikipedia's database schema looks like? I recently read this thread from
I think I read every single web page relating to this problem but I
Almost every Java book I read talks about using the interface as a way
I've developed some web-based applications till now using PHP, Python and Java. But some
I read at multiple places that Boost.Signals is not threadsafe but I haven't found
I spin off a new thread that reads data from a database. Every X
I've read the the restrictions for EJBs and several answers here on stackoverflow but

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.