""""Script demonstrating how subprocess.Popen() does work with a file object that has been seek'ed only once. """ import subprocess # Open a file (and call seek on it) rawfile = file('hello.txt', 'rb') rawfile.readline() rawfile.seek(0) # Seek back to the start of the file, changing the file pointer # Run cat to print the contents of the file program_arguments = ["cat"] process_object = subprocess.Popen(program_arguments, stdin=rawfile, \ stdout=subprocess.PIPE, stderr=subprocess.PIPE) print "File contents from Popen() call to cat:" print process_object.stdout.read() process_object.wait()