Subprocess confusion: how file-like must stdin be?
Fredrik Lundh
fredrik at pythonware.com
Fri Aug 18 10:30:30 EDT 2006
Cameron Laird wrote:
> Your interactive session does indeed exhibit the behavior that
> puzzles me. My expectation was that StringIO and the std*
> parameters to Popen() were made for each other; certainly there
> are many cases where stdout and stderr can be redirected *to* a
> StringIO. Is it simply the case that stdin demands a more
> file-like object? While that disappoints me, I certainly can
> program around it. My question, then: does stdin effectively
> require something really in the filesystem, or perhaps the
> stdout of a previous subprocess? Is there no built-in way to
> feed it an in-memory construct?
set the appropriate stream to subprocess.PIPE, and write to it.
p = subprocess.Popen(..., stdin=subprocess.PIPE)
p.stdin.write("hello")
p.stdin.close() # signal end of file
</F>
More information about the Python-list
mailing list