Subprocess confusion: how file-like must stdin be?

Cameron Laird claird at lairds.us
Thu Aug 17 13:16:25 EDT 2006


Question:
  import subprocess, StringIO

  input = StringIO.StringIO("abcdefgh\nabc\n")
      # I don't know of a compact, evocative, and
      # cross-platform way to exhibit this behavior.
      # For now, depend on cat(1).
  p = subprocess.Popen(["cat"], stdout = subprocess.PIPE, 
				stdin = response)

Why this is a question:
A.  it tosses an AttributeError.
B.  I *expected* it to do the equivalent of
      cat << HERE 
      abcdefgh
      abc
      HERE

In <URL: http://docs.python.org/dev/lib/node530.html >, I read "Valid
values are ... an existing file object ..."  Even though StringIO is
a "file-like object", it lacks a fileno.  Is there a way to get what
I'm after?



More information about the Python-list mailing list