for even more control over the streams of spawned programswe can employ the subprocess module we introduced in the preceding as we learned earlierthis module can emulate os popen functionalitybut it can also achieve feats such as bidirectional stream communication (accessing both program' input and outputand tying the output of one program to the input of another for instancethis module provides multiple ways to spawn program and get both its standard output text and exit status here are three common ways to leverage this module to start program and redirect its output stream (recall from that you may need to pass shell=true argument to popen and call to make this section' examples work on unix-like platforms as they are coded here) :\pp \system\streamspython from subprocess import popenpipecall call('python hello-out py'hello shell world pipe popen('python hello-out py'stdout=pipepipe communicate()[ 'hello shell world\ \npipe returncode pipe popen('python hello-out py'stdout=pipepipe stdout read( 'hello shell world\ \npipe wait( convenience (stdoutstderrexit status exit status the call in the first of these three techniques is just convenience function (there are more of these which you can look up in the python library manual)and the communicate in the second is roughly convenience for the third (it sends data to stdinreads data from stdout until end-of-fileand waits for the process to end)redirecting and connecting to the spawned program' input stream is just as simplethough bit more complex than the os popen approach with 'wfile mode shown in the preceding section (as mentioned in the last os popen is implemented with subprocessand is thus itself just something of convenience function today)pipe popen('python hello-in py'stdin=pipepipe stdin write( 'pokey\ ' pipe stdin close(pipe wait( open('hello-in txt'read('hello pokey\ script execution context output sent to file