Subprocess confusion: how file-like must stdin be?
Nick Craig-Wood
nick at craig-wood.com
Fri Aug 18 04:30:03 EDT 2006
Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Thu, 17 Aug 2006 17:16:25 +0000, claird at lairds.us (Cameron Laird)
> declaimed the following in comp.lang.python:
>
> > Question:
> > import subprocess, StringIO
> >
> > input = StringIO.StringIO("abcdefgh\nabc\n")
>
> Here you override the builtin function "input()"
> > # 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)
>
> Here you specify the non-existant "response"
Assume the OP meant to write this
>>> import subprocess, StringIO
>>> inp = StringIO.StringIO("abcdefgh\nabc\n")
>>> p = subprocess.Popen(["cat"], stdout = subprocess.PIPE, stdin = inp)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/subprocess.py", line 534, in __init__
(p2cread, p2cwrite,
File "/usr/lib/python2.4/subprocess.py", line 830, in _get_handles
p2cread = stdin.fileno()
AttributeError: StringIO instance has no attribute 'fileno'
>>>
--
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick
More information about the Python-list
mailing list