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

C

chad

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?
 
C

Chris Rebert

       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
 
A

Aahz

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?

You really should do this instead, untested:

broadcast = s.Popen(['wall'], stdin=s.PIPE)
while 1:
broadcast.write('test\n')
time.sleep(1)
--
Aahz ([email protected]) <*> 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top