Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How would I do a continuous write over a pipe in the following code...

2 views
Skip to first unread message

chad

unread,
Feb 20, 2010, 3:46:24 PM2/20/10
to
Given the following....

#!/usr/bin/python

import subprocess as s

broadcast = s.Popen("echo test | wall", shell=True,stdout=s.PIPE)

out = broadcast.stdout
while 1:
out
broadcast.wait()

broadcast.stdout.close()


The code only executes once. What I want to do is be able to
continuously write over the pipe once it is open. I could put
s.Popen() inside the while loop, but that seems a bit too messy. So is
there some way to just open the pipe once, and once it is open, just
continuously write over it vs just opening and closing the pipe every
time?

Message has been deleted

Chris Rebert

unread,
Feb 21, 2010, 4:18:28 PM2/21/10
to Dennis Lee Bieber, pytho...@python.org
On Sun, Feb 21, 2010 at 1:09 PM, Dennis Lee Bieber
<wlf...@ix.netcom.com> wrote:
> On Sat, 20 Feb 2010 12:46:24 -0800 (PST), chad <cda...@gmail.com>
> declaimed the following in comp.lang.python:

>
>> Given the following....
>>
>> #!/usr/bin/python
>>
>> import subprocess as s
>>
>> broadcast = s.Popen("echo test | wall", shell=True,stdout=s.PIPE)
>>
>> out = broadcast.stdout
>> while 1:
>>     out
>
>        Does nothing... "out" is a name bound to the object identified by
> "broadcast.stdout"...
>
>        It does nothing unless it is called as...
>
>        out(somedata)

I'm pretty sure you meant:

out.write(somedata)

Cheers,
Chris
--
http://blog.rebertia.com

Message has been deleted

Aahz

unread,
Feb 25, 2010, 7:51:01 PM2/25/10
to
In article <9d0f6456-97c7-4bde...@t31g2000prh.googlegroups.com>,

You really should do this instead, untested:

broadcast = s.Popen(['wall'], stdin=s.PIPE)
while 1:
broadcast.write('test\n')
time.sleep(1)
--
Aahz (aa...@pythoncraft.com) <*> http://www.pythoncraft.com/

"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer

0 new messages