[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Using popen with 0,1,2,3,4 streams

Jan Koprowski

12/2/2007 11:10:00 AM

Hi !

I try to run command system and get streams handlers to 0 (stdin),
1(stdout), 2(stderr), 3(myOwnStdIn1), 4(myOwnStdIn2). I do something
like that in PHP by proc_open and table of pipes, but here I don't
know how I can get handlers to process streams. I know that this code
is bad but I think something like this:

process = popen('command', 'w+');
stdin = process.new(0, "w");
stdout = process.new(1, "r");

etc...

But new is a static method. What i should to do ?
10 Answers

Judson Lester

12/4/2007 12:32:00 AM

0

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

Jan,

You might look at popen3 in the standard library. I don't think it quite
does what you need (since it returns an array if three pipes: stdin, stdout
and stderr for the subprocess) but the code is short if a little arcane, and
might point you in the right direction to figure this out.

Judson

On Dec 2, 2007 3:10 AM, Jan Koprowski <Jan.Koprowski@gmail.com> wrote:

> Hi !
>
> I try to run command system and get streams handlers to 0 (stdin),
> 1(stdout), 2(stderr), 3(myOwnStdIn1), 4(myOwnStdIn2). I do something
> like that in PHP by proc_open and table of pipes, but here I don't
> know how I can get handlers to process streams. I know that this code
> is bad but I think something like this:
>
> process = popen('command', 'w+');
> stdin = process.new(0, "w");
> stdout = process.new(1, "r");
>
> etc...
>
> But new is a static method. What i should to do ?
>
>


--
Your subnet is currently 169.254.0.0/16. You are likely to be eaten by a
grue.

Tim Pease

12/4/2007 4:58:00 PM

0

On Dec 3, 2007 5:32 PM, Judson Lester <nyarly@gmail.com> wrote:
> Jan,
>
> You might look at popen3 in the standard library. I don't think it quite
> does what you need (since it returns an array if three pipes: stdin, stdout
> and stderr for the subprocess) but the code is short if a little arcane, and
> might point you in the right direction to figure this out.
>
> Judson
>
>
> On Dec 2, 2007 3:10 AM, Jan Koprowski <Jan.Koprowski@gmail.com> wrote:
>
> > Hi !
> >
> > I try to run command system and get streams handlers to 0 (stdin),
> > 1(stdout), 2(stderr), 3(myOwnStdIn1), 4(myOwnStdIn2). I do something
> > like that in PHP by proc_open and table of pipes, but here I don't
> > know how I can get handlers to process streams. I know that this code
> > is bad but I think something like this:
> >
> > process = popen('command', 'w+');
> > stdin = process.new(0, "w");
> > stdout = process.new(1, "r");
> >
> > etc...
> >
> > But new is a static method. What i should to do ?
> >

Also take a look at open4 and systemu. You can find both at the
codeforpeople project on RubyForge. They, too, will offer some good
insight on what you want to do, though neither does precisely what you
need.

<http://rubyforge.org/projects/codefor...

Blessings,
TwP

Jan Koprowski

12/6/2007 8:20:00 AM

0

On 4 Gru, 17:58, Tim Pease <tim.pe...@gmail.com> wrote:
> On Dec 3, 2007 5:32 PM, Judson Lester <nya...@gmail.com> wrote:
>
>
>
> > Jan,
>
> > You might look at popen3 in the standard library. I don't think it quite
> > does what you need (since it returns an array if three pipes: stdin, stdout
> > and stderr for the subprocess) but the code is short if a little arcane, and
> > might point you in the right direction to figure this out.
>
> > Judson
>
> > On Dec 2, 2007 3:10 AM, Jan Koprowski <Jan.Koprow...@gmail.com> wrote:
>
> > > Hi !
>
> > > I try to run command system and get streams handlers to 0 (stdin),
> > > 1(stdout), 2(stderr), 3(myOwnStdIn1), 4(myOwnStdIn2). I do something
> > > like that in PHP by proc_open and table of pipes, but here I don't
> > > know how I can get handlers to process streams. I know that this code
> > > is bad but I think something like this:
>
> > > process =popen('command', 'w+');
> > > stdin = process.new(0, "w");
> > > stdout = process.new(1, "r");
>
> > > etc...
>
> > > But new is a static method. What i should to do ?
>
> Also take a look at open4 and systemu. You can find both at the
> codeforpeople project on RubyForge. They, too, will offer some good
> insight on what you want to do, though neither does precisely what you
> need.
>
> <http://rubyforge.org/projects/codefor...
>
> Blessings,
> TwP

Thank You for respond. I know that I can use only 3 pipes. But I think
I can look for open4 and try to write something similar. Thanks !

Jan Koprowski

12/6/2007 8:39:00 AM

0

On 4 Gru, 17:58, Tim Pease <tim.pe...@gmail.com> wrote:
> On Dec 3, 2007 5:32 PM, Judson Lester <nya...@gmail.com> wrote:
>
>
>
> > Jan,
>
> > You might look at popen3 in the standard library. I don't think it quite
> > does what you need (since it returns an array if three pipes: stdin, stdout
> > and stderr for the subprocess) but the code is short if a little arcane, and
> > might point you in the right direction to figure this out.
>
> > Judson
>
> > On Dec 2, 2007 3:10 AM, Jan Koprowski <Jan.Koprow...@gmail.com> wrote:
>
> > > Hi !
>
> > > I try to run command system and get streams handlers to 0 (stdin),
> > > 1(stdout), 2(stderr), 3(myOwnStdIn1), 4(myOwnStdIn2). I do something
> > > like that in PHP by proc_open and table of pipes, but here I don't
> > > know how I can get handlers to process streams. I know that this code
> > > is bad but I think something like this:
>
> > > process =popen('command', 'w+');
> > > stdin = process.new(0, "w");
> > > stdout = process.new(1, "r");
>
> > > etc...
>
> > > But new is a static method. What i should to do ?
>
> Also take a look at open4 and systemu. You can find both at the
> codeforpeople project on RubyForge. They, too, will offer some good
> insight on what you want to do, though neither does precisely what you
> need.
>
> <http://rubyforge.org/projects/codefor...
>
> Blessings,
> TwP

U try to write something like this:

#
# To change this template, choose Tools | Templates
# and open the template in the editor.
require 'fcntl'
require 'timeout'
require 'thread'

class Broker_process3

READ = 0 # Consts to explicite mark read
WRITE = 1 # and write pipes
@stdin
@stdout
@stderr

def initialize

end

def self.run (command, params)
pw, pr, pe, pl, pp = IO.pipe, IO.pipe, IO.pipe, IO.pipe, IO.pipe
pl.last.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
pp.last.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)

pid = fork {
pw.last.close
STDIN.reopen pw.first
pw.first.close

pr.first.close
STDOUT.reopen pr.last
pr.last.close

pe.first.close
STDERR.reopen pe.last
pe.last.close

pl.last.close
pp.last.close

STDOUT.sync = STDERR.sync = true

exec(*command)
}

[pw.first, pr.last, pe.last, pl.first, pp.first].each{|fd|
fd.close}

pl.last.write("login"); // ERROR HERE
pl.last.close
pp.last.write("haslo");
pp.last.close

pw.last.close
out = pr.first.readlines
pr.first.close
pe.first.close
puts out;
end
end

but in // ERROR HERE I get:

./broker_process3.rb:48:in `write': Broken pipe (Errno::EPIPE)
from ./broker_process3.rb:48:in `run'
from /home/johny/NetBeansProjects/zhradmin/lib/main.rb:12

Jan Koprowski

12/6/2007 8:39:00 AM

0

On 4 Gru, 17:58, Tim Pease <tim.pe...@gmail.com> wrote:
> On Dec 3, 2007 5:32 PM, Judson Lester <nya...@gmail.com> wrote:
>
>
>
> > Jan,
>
> > You might look at popen3 in the standard library. I don't think it quite
> > does what you need (since it returns an array if three pipes: stdin, stdout
> > and stderr for the subprocess) but the code is short if a little arcane, and
> > might point you in the right direction to figure this out.
>
> > Judson
>
> > On Dec 2, 2007 3:10 AM, Jan Koprowski <Jan.Koprow...@gmail.com> wrote:
>
> > > Hi !
>
> > > I try to run command system and get streams handlers to 0 (stdin),
> > > 1(stdout), 2(stderr), 3(myOwnStdIn1), 4(myOwnStdIn2). I do something
> > > like that in PHP by proc_open and table of pipes, but here I don't
> > > know how I can get handlers to process streams. I know that this code
> > > is bad but I think something like this:
>
> > > process =popen('command', 'w+');
> > > stdin = process.new(0, "w");
> > > stdout = process.new(1, "r");
>
> > > etc...
>
> > > But new is a static method. What i should to do ?
>
> Also take a look at open4 and systemu. You can find both at the
> codeforpeople project on RubyForge. They, too, will offer some good
> insight on what you want to do, though neither does precisely what you
> need.
>
> <http://rubyforge.org/projects/codefor...
>
> Blessings,
> TwP

U try to write something like this:

#
# To change this template, choose Tools | Templates
# and open the template in the editor.
require 'fcntl'
require 'timeout'
require 'thread'

class Broker_process3

READ = 0 # Consts to explicite mark read
WRITE = 1 # and write pipes
@stdin
@stdout
@stderr

def initialize

end

def self.run (command, params)
pw, pr, pe, pl, pp = IO.pipe, IO.pipe, IO.pipe, IO.pipe, IO.pipe
pl.last.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
pp.last.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)

pid = fork {
pw.last.close
STDIN.reopen pw.first
pw.first.close

pr.first.close
STDOUT.reopen pr.last
pr.last.close

pe.first.close
STDERR.reopen pe.last
pe.last.close

pl.last.close
pp.last.close

STDOUT.sync = STDERR.sync = true

exec(*command)
}

[pw.first, pr.last, pe.last, pl.first, pp.first].each{|fd|
fd.close}

pl.last.write("login"); // ERROR HERE
pl.last.close
pp.last.write("haslo");
pp.last.close

pw.last.close
out = pr.first.readlines
pr.first.close
pe.first.close
puts out;
end
end

but in // ERROR HERE I get:

./broker_process3.rb:48:in `write': Broken pipe (Errno::EPIPE)
from ./broker_process3.rb:48:in `run'
from /home/johny/NetBeansProjects/zhradmin/lib/main.rb:12

David Johnston

11/5/2013 7:30:00 PM

0

On 11/5/2013 10:28 AM, Stephen Wilson wrote:
> "Adam H. Kerman" <ahk@chinet.com> wrote in message
> news:l5ardc$63s$2@news.albasani.net...
>> Stephen Wilson <stephen.wilson2004nospam@ntlworld.com> wrote:
>>
>>> The Name of the Doctor makes it clear that [John] Hurt is a version of
>>> the Doctor. Smith knows him. He therefore is not from Smith's future. . .
>>> .
>>
>> How did you rule out The Doctor not knowing future selves given that we've
>> seen this? If Hurt is a past self but knows Smith, then a past self knew
>> a future self in that episode
>
> The Doctor has never known his future selves. On the few occasions a past
> Doctor has met a future Doctor, the past Doctor's memory of the event was
> wiped.

So the Doctor's memory of the Valeyard was wiped?

Your Name

11/5/2013 8:09:00 PM

0

In article <l5ardc$63s$2@news.albasani.net>, Adam H. Kerman
<ahk@chinet.com> wrote:

> Stephen Wilson <stephen.wilson2004nospam@ntlworld.com> wrote:
>
> >The Name of the Doctor makes it clear that [John] Hurt is a version of
> >the Doctor. Smith knows him. He therefore is not from Smith's future. . . .
>
> How did you rule out The Doctor not knowing future selves given that we've
> seen this? If Hurt is a past self but knows Smith, then a past self knew
> a future self in that episode.
>
> Nothing we've seen rules out Matt Smith meeting a future incarnation
> of The Doctor. Not even all that dialogue we've heard during Smith seasons
> and in the past of not crossing time lines and not contaminating time lines.
> It's often done on this show, which has no rules.

You're wasting your time. The moron is so blinkered into their only
being one possible solution that he simply won't every believe anything
else. If he turns out to be wrong he's going to be bitterly confused
and probably have a mental breakdown. :-

Your Name

11/5/2013 8:13:00 PM

0

In article <l5bfcb$gst$2@news.albasani.net>, Adam H. Kerman
<ahk@chinet.com> wrote:

> Stephen Wilson <stephen.wilson2004nospam@ntlworld.com> wrote:
> >"Adam H. Kerman" <ahk@chinet.com> wrote:
> >>Stephen Wilson <stephen.wilson2004nospam@ntlworld.com> wrote:
>
> >>>The Name of the Doctor makes it clear that [John] Hurt is a version
> >>>of the Doctor. Smith knows him. He therefore is not from Smith's
> >>>future. . . .
>
> >>How did you rule out The Doctor not knowing future selves given that we've
> >>seen this? If Hurt is a past self but knows Smith, then a past self knew
> >>a future self in that episode
>
> >The Doctor has never known his future selves. On the few occasions a past
> >Doctor has met a future Doctor, the past Doctor's memory of the event was
> >wiped.
>
> I don't recall dialogue to that effect in "The Three Doctors", "The Five
> Doctors", or "The Two Doctors". Was there?
>
> >On the few occasions the Doctor has had the opportunity to find out
> >about his own future (eg via River Song), he has completely refused to do
> >so.
>
> Except he did indeed learn what River saw in "The Impossible Astronaut",
> and created a situation in which River would still see it.

We also have no way of knowing what the consequences are of him
entering his own timestream vortex. Maybe when he's inside that it
causes him to see and know his entire lifetime ... of course the
blinkered braindead moron simply doesn't believe it was the ENTIRE
lifetime and magically stopped at Matt Smith's Doctor.

doctor

11/5/2013 9:28:00 PM

0

In article <ZL9eu.8309$Mn5.5278@fx25.am4>,
Stephen Wilson <stephen.wilson2004nospam@ntlworld.com> wrote:
>
>"The Doctor" <doctor@doctor.nl2k.ab.ca> wrote in message
>news:l59eqr$ruu$1@gallifrey.nk.ca...
>> In article <TiWdu.69570$5L5.23407@fx17.am4>,
>> Stephen Wilson <stephen.wilson2004nospam@ntlworld.com> wrote:
>>>
>>>"David Johnston" <David@block.net> wrote in message
>>>news:l58v32$a0m$1@dont-email.me...
>>>> On 11/4/2013 10:52 AM, Stephen Wilson wrote:
>>>>> "The Doctor" <doctor@doctor.nl2k.ab.ca> wrote in message
>>>>> news:l58dpg$omb$1@gallifrey.nk.ca...
>>>>>>>
>>>>>>>
>>>>>>> 20 days and counting.
>>>>>>>
>>>>>>> Is John Hurt really the Valeyard?
>>>>>
>>>>> No he's not. John Hurt is playing the 9th Doctor (i.e. the one before
>>>>> Eccleston).
>>>>
>>>> How do you know that?
>>>
>>>I can't see anywhere else in the Doctor's timeline you could fit him in.
>>>
>>>The Name of the Doctor makes it clear that Hurt is a version of the
>>>Doctor.
>>>Smith knows him. He therefore is not from Smith's future. I suppose you
>>>could assume Hartnell was not the first Doctor. Or you could assume there
>>>was an extra Doctor between Troughton and Pertwee. However neither of
>>>these
>>>options seem likely. When we first met the 9th Doctor (i.e. Eccleston),
>>>there were hints that he'd only recently regenerated. Also somewhere
>>>between
>>>McGann and Eccleston there was a Time War. Who was involved in the Time
>>>War - McGann or Eccleston? Or maybe... Well there's the most likely gap.
>>>Between Eccleston and McGann. So it becomes the Hurt Doctor who destroyed
>>>both the Time Lords and the Daleks and somehow escapes but in doing so
>>>regenerates into Eccleston.
>>>
>>>This is what makes most sense given what has been seen and said so far. I
>>>might be completely wrong and perhaps Moffat has a completely different
>>>idea. In the meantime, do you have any better suggestions?
>>>
>>>
>>>
>>
>> Check out the Web.
>
>Why?
>

Because there is a mention.

>
>
>---
>This email is free from viruses and malware because avast! Antivirus protection is active.
>http://www...
>


--
Member - Liberal International This is doctor@nl2k.ab.ca Ici doctor@nl2k.ab.ca
God,Queen and country!Never Satan President Republic!Beware AntiChrist rising!
http://www.fullyfollow.m... Look at Psalms 14 and 53 on Atheism
23 Nov 2013 a Big day indeed

Stephen Wilson

11/5/2013 11:49:00 PM

0


"The Doctor" <doctor@doctor.nl2k.ab.ca> wrote in message
news:l5bnt6$48p$1@gallifrey.nk.ca...
> In article <ZL9eu.8309$Mn5.5278@fx25.am4>,
> Stephen Wilson <stephen.wilson2004nospam@ntlworld.com> wrote:
>>
>>"The Doctor" <doctor@doctor.nl2k.ab.ca> wrote in message
>>news:l59eqr$ruu$1@gallifrey.nk.ca...
>>> In article <TiWdu.69570$5L5.23407@fx17.am4>,
>>> Stephen Wilson <stephen.wilson2004nospam@ntlworld.com> wrote:
>>>>
>>>>"David Johnston" <David@block.net> wrote in message
>>>>news:l58v32$a0m$1@dont-email.me...
>>>>> On 11/4/2013 10:52 AM, Stephen Wilson wrote:
>>>>>> "The Doctor" <doctor@doctor.nl2k.ab.ca> wrote in message
>>>>>> news:l58dpg$omb$1@gallifrey.nk.ca...
>>>>>>>>
>>>>>>>>
>>>>>>>> 20 days and counting.
>>>>>>>>
>>>>>>>> Is John Hurt really the Valeyard?
>>>>>>
>>>>>> No he's not. John Hurt is playing the 9th Doctor (i.e. the one before
>>>>>> Eccleston).
>>>>>
>>>>> How do you know that?
>>>>
>>>>I can't see anywhere else in the Doctor's timeline you could fit him in.
>>>>
>>>>The Name of the Doctor makes it clear that Hurt is a version of the
>>>>Doctor.
>>>>Smith knows him. He therefore is not from Smith's future. I suppose you
>>>>could assume Hartnell was not the first Doctor. Or you could assume
>>>>there
>>>>was an extra Doctor between Troughton and Pertwee. However neither of
>>>>these
>>>>options seem likely. When we first met the 9th Doctor (i.e. Eccleston),
>>>>there were hints that he'd only recently regenerated. Also somewhere
>>>>between
>>>>McGann and Eccleston there was a Time War. Who was involved in the Time
>>>>War - McGann or Eccleston? Or maybe... Well there's the most likely gap.
>>>>Between Eccleston and McGann. So it becomes the Hurt Doctor who
>>>>destroyed
>>>>both the Time Lords and the Daleks and somehow escapes but in doing so
>>>>regenerates into Eccleston.
>>>>
>>>>This is what makes most sense given what has been seen and said so far.
>>>>I
>>>>might be completely wrong and perhaps Moffat has a completely different
>>>>idea. In the meantime, do you have any better suggestions?
>>>>
>>>>
>>>>
>>>
>>> Check out the Web.
>>
>>Why?
>>
>
> Because there is a mention.

So what?



---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www...