I&#39;ve now seen a common problem come up several times. And, I imagine there is a common solution to this problem that I don&#39;t know.<div><br></div><div>About a year ago, I wrote an automatic script that would automatically do an &#39;svn export&#39; of certain branches of a tree depending upon what menu option the customer chose. When I did the svn export, I used subprocess.Popen.</div>
<div><br></div><div>The pattern was similar to the following:</div><div><br></div><div>print &quot;&quot;&quot;This output is being buffered so I can read the version number.</div><div>
<p class="p1">    ....  I&#39;m not stuck, just busy exporting files....</p><p class="p1">&quot;&quot;&quot;</p>
<p class="p2">.....</p>
<p class="p1">process = subprocess.Popen([&#39;svn&#39;, &#39;export&#39;, repository, repo_name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)</p></div><div><div>stdoutdata, stderrdata = process.communicate()</div></div>
<div><br></div><div><br></div><div>I printed &quot;please wait&quot; and then printed the data given when the process was done (stdoutdata). It wasn&#39;t ideal but, it was sufficient for the time. If I were to have gone for the best fix, I would probably have learned the API for subversion to integrate directly into python.</div>
<div><br></div><div>However, another BayPIGgie is having the same issue. He is using a command to start a CD burner from the command line and wants to print the output as it is being created from the command line.</div><div>
<br></div><div>I can see that to solve this we wouldn&#39;t use the communicate() convenience function. A few &#39;hackish&#39; ways that may solve this, but I&#39;m looking for the common pattern that is used when other pythonista run up against this problem. I also want to ensure that I don&#39;t have a &#39;hack&#39; that causes a deadlock only to discover this much later after I&#39;ve implemented the pattern a few times.</div>
<div><br></div><div>To help keep the conversation more focused, I&#39;ve created two tiny test programs for a test case:</div><div>1) A C command line program that we have no control over changing within python, and</div>
<div>2) A Python program that calls that the c-program (baypiggies_demo):</div><div><br></div><div>Compile command line so output is same as expected by Python program:</div><div>gcc -pedantic baypiggies_demo.c -o baypiggies_demo</div>
<div><br></div><div><br><div>---- start of c program: File: baypiggies_demo.c ---</div><div><div>#include &lt;stdio.h&gt;</div><div>#include &lt;unistd.h&gt;</div><div><br></div><div>int</div><div>main()</div><div>{</div>
<div>    int             i = 0;</div>
<div><br></div><div>    printf(&quot;Silly output for monitoring...\n&quot;);</div><div>    for (i = 0; i &lt;= 10; i++) {</div><div>        printf(&quot;Counting... %d\n&quot;, i);</div><div>        sleep(1);</div><div>
    }</div>
<div>}</div></div><div>--- end of c program ---</div><div><br></div><div><br></div><div><br></div><div>--- start of python program to demonstrate. File baypiggies.py ---</div><div><div>import subprocess</div><div><br></div>

<div>print &quot;Just waiting....&quot;</div><div><br></div><div>process = subprocess.Popen([&#39;./baypiggies_demo&#39;],</div><div>                    stdout=subprocess.PIPE)</div><div><br></div><div>stdoutdata, stderrdata = process.communicate()</div>

<div><br></div><div>print &quot;Well, NOW I get it.. :( &quot;</div><div>print stdoutdata</div><div>--- end baypiggies.py --</div><div><br></div><div><br></div><div><br></div><div>Has anyone else ran into this before? What&#39;s the classic pattern used?</div>
<div><br></div><div><br></div><div>Thanks in advance,</div><div><br></div><div><br></div><div>Glen</div>-- <br>Whatever you can do or imagine, begin it;<br>
boldness has beauty, magic, and power in it.<br><br>-- Goethe <br>
</div>
</div>