-1

I want to run a process from a python script, blocking while it runs, and writing the output of the process to stdout.

How would I do this?

I looked at the documentation for 'subprocess' but couldn't work it out.

Editing this question to explain how it's different, as requested: See existing text above: and writing the output of the process to stdout

3
  • Printing to stdout: stackoverflow.com/questions/2082850/… Commented Mar 3, 2016 at 11:59
  • Thanks - waiting until the command is done is one aspect of what I'm after. I could achieve that with call, I think (that's what I've found). One extra feature is that I also want the output to be streamed to my console. Commented Mar 3, 2016 at 12:13
  • why not just use subprocess.check_call([command])? Commented Mar 3, 2016 at 12:17

2 Answers 2

0

You can use the wait() method for that.

For example:

# main_script.py #some code p1 = subprocess.Popen(['/path/to/process.sh'], shell=True) p1.wait() #rest of code when process is done 
Sign up to request clarification or add additional context in comments.

Comments

0

you can use object.communicate()[0]

p=subprocess.Popen(["python","1st.py"],stdin=PIPE,stdout=PIPE) print p.communicate()[0] Communicate() will hold the last processed process output. 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.