[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

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

Chad

2/20/2010 8:46:00 PM

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?
4 Answers

Dennis Lee Bieber

2/21/2010 9:10:00 PM

0

On Sat, 20 Feb 2010 12:46:24 -0800 (PST), chad <cdalten@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)
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

Chris Rebert

2/21/2010 9:18:00 PM

0

On Sun, Feb 21, 2010 at 1:09 PM, Dennis Lee Bieber
<wlfraed@ix.netcom.com> wrote:
> On Sat, 20 Feb 2010 12:46:24 -0800 (PST), chad <cdalten@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.re...

Dennis Lee Bieber

2/22/2010 12:27:00 AM

0

On Sun, 21 Feb 2010 13:18:28 -0800, Chris Rebert <clp2@rebertia.com>
declaimed the following in comp.lang.python:

> I'm pretty sure you meant:
>
> out.write(somedata)
>
<heh>

I was too focused on the lack of any sort of call (ie, no parens on
the line) to work down the next level of methods...
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

aahz

2/26/2010 12:51:00 AM

0

In article <9d0f6456-97c7-4bde-8e07-9576b02f91f9@t31g2000prh.googlegroups.com>,
chad <cdalten@gmail.com> wrote:
>
>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 (aahz@pythoncraft.com) <*> http://www.python...

"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