Pipe stdin to a spawned process with subprocess module?

This is the place for queries that don't fit in any of the other categories.

Pipe stdin to a spawned process with subprocess module?

Postby soundeffects » Sun Aug 03, 2014 8:35 pm

I'm learning Python and using 2.7.6.

Is there an recommended way to pipe stdin from a string object to a spawned process using subprocess module? For pipes, the documentation recommends using the
Code: Select all
method of a Popen instance, and it even includes a warning to
Use communicate() rather than .stdin.write, .stdout.read or .stderr.read to avoid deadlocks due to any of the other OS pipe buffers filling up and blocking the child process.
But the communicate() waits for the process to finish, while I need the process to persist.

I recognize that one can write a subclass of Popen and override the communicate() method, replacing the call to wait() therein with a call to poll(). But that seems excessive, and I'm prone to introducing unforeseen errors.
Last edited by Yoriz on Sun Aug 03, 2014 10:51 pm, edited 1 time in total.
Reason: First post lock.
Posts: 1
Joined: Sun Aug 03, 2014 8:30 pm

Re: Pipe stdin to a spawned process with subprocess module?

Postby Yoriz » Sun Aug 03, 2014 10:51 pm

Welcome to the forum, Please read the new users read this link in my signature.
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Posts: 1671
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 4 guests