Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #2532

Re: reading and writing to child process with streams in ruby

From Brian Candler <b.candler@pobox.com>
Newsgroups comp.lang.ruby
Subject Re: reading and writing to child process with streams in ruby
Date Fri, 8 Apr 2011 08:32:48 -0500
Organization Service de news de lacave.net
Lines 26
Message-ID <25ff3d42fe12472e3f3c8ea44c2dbc19@ruby-forum.com> (permalink)
References <09ce70f0-118a-4e4d-82f1-7d88436233ff@l39g2000yqh.googlegroups.com>
NNTP-Posting-Host bristol.highgroove.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace talisker.lacave.net 1302269616 1822 65.111.164.187 (8 Apr 2011 13:33:36 GMT)
X-Complaints-To abuse@lacave.net
NNTP-Posting-Date Fri, 8 Apr 2011 13:33:36 +0000 (UTC)
In-Reply-To <09ce70f0-118a-4e4d-82f1-7d88436233ff@l39g2000yqh.googlegroups.com>
X-Received-From This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway
X-Mail-Count 381198
X-Ml-Name ruby-talk
X-Rubymirror Yes
X-Ruby-Talk <25ff3d42fe12472e3f3c8ea44c2dbc19@ruby-forum.com>
Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.stben.net!talisker.lacave.net!lacave.net!not-for-mail
Xref x330-a1.tempe.blueboxinc.net comp.lang.ruby:2532

Show key headers only | View raw


mpurdy wrote in post #991644:
> echo -n "username: "

You are sending just "username: " without a trailing newline.

>          line = stdout.read

Here you are reading from stdout until the end-of-file (i.e. until the 
other side terminates or closes the file). This will wait forever.

Two possible solutions:

1. Change your shell script to send data ending with a newline, then use 
'gets' in the ruby code.

2. More generally, use expect.rb in the standard library. Then you can 
wait for a particular sequence of characters, e.g. /name: /, before 
continuing.

HTH,

Brian.

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

reading and writing to child process with streams in ruby mpurdy <mpurdy1973usergroups@gmail.com> - 2011-04-07 20:58 -0700
  Re: reading and writing to child process with streams in ruby "Y. NOBUOKA" <nobuoka@r-definition.com> - 2011-04-08 03:03 -0500
    Re: reading and writing to child process with streams in ruby mpurdy <mpurdy1973usergroups@gmail.com> - 2011-04-08 18:44 -0700
  Re: reading and writing to child process with streams in ruby Brian Candler <b.candler@pobox.com> - 2011-04-08 08:32 -0500
    Re: reading and writing to child process with streams in ruby mpurdy <mpurdy1973usergroups@gmail.com> - 2011-04-08 18:48 -0700

csiph-web