I think the problem is when you do STDIN.dup, you're duplicating the
already redirected STDIN.
···
On Apr 17, 2008, at 9:30 PM, Xie Hanjian wrote:
a @ http://codeforpeople.com/
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama
I'm afraid the problem is the same: you can't interact with the program
after data has been read. any function like getch() will try to read input
from the file to which stdin was redirected instead of your console.
Thanks
Jan
* Daniel Finnie <dan@danfinnie.com> [2008-04-19 02:08:11 +0900]:
···
Hi,
I think ARGF might work for your needs:
data = ARGF.read
Give it a try,
Dan
On 4/17/08, Xie Hanjian <jan.h.xie@gmail.com> wrote:
> Hi,
>
> I want to know if there's a more 'portable' way to do this in ruby:
>
> I hope my programe will accept data from redirected stdin or pipe, like
>
> cat bar | foo.rb
> foo.rb < bar
>
> And after read the data I want to interact with the foo.rb in console.
> The problem is stdin has been redirected so I have to:
>
> STDIN.reopen('/dev/tty')
>
> Hardcoding a string in the script seems not good. Any suggestions?
>
> Thanks
> Jan
>
>
> --
> jan=callcc{|jan|jan};jan.call(jan)
>
>
I'm afraid the problem is the same: you can't interact with the program
after data has been read. any function like getch() will try to read input
from the file to which stdin was redirected instead of your console.
You can check if you are getting data from a pipe by asking
$stdin.tty? and act accordingly.
See http://p.ramaze.net/1144 for a short example.
On Sat, Apr 19, 2008 at 1:40 PM, Xie Hanjian <jan.h.xie@gmail.com> wrote:
Thanks
Jan
* Daniel Finnie <dan@danfinnie.com> [2008-04-19 02:08:11 +0900]:
> Hi,
>
> I think ARGF might work for your needs:
>
> data = ARGF.read
>
> Give it a try,
> Dan
>
> On 4/17/08, Xie Hanjian <jan.h.xie@gmail.com> wrote:
> > Hi,
> >
> > I want to know if there's a more 'portable' way to do this in ruby:
> >
> > I hope my programe will accept data from redirected stdin or pipe, like
> >
> > cat bar | foo.rb
> > foo.rb < bar
> >
> > And after read the data I want to interact with the foo.rb in console.
> > The problem is stdin has been redirected so I have to:
> >
> > STDIN.reopen('/dev/tty')
> >
> > Hardcoding a string in the script seems not good. Any suggestions?
> >
> > Thanks
> > Jan
> >
> >
> > --
> > jan=callcc{|jan|jan};jan.call(jan)
> >
> >
>
I'm afraid the problem is the same: you can't interact with the program
after data has been read. any function like getch() will try to read input
from the file to which stdin was redirected instead of your console.
You can check if you are getting data from a pipe by asking
$stdin.tty? and act accordingly.
See http://p.ramaze.net/1144 for a short example.
*Completely* OT here. I had this message open on the screen while I was
showing my mother something on my desk. We talked about for a bit and I
showed her whatever it was, and then she went to leave my room. As she left,
she looked back at me and said, "Make that con and you're onto a winner!". I
had no idea what she was saying, and asked "what?". She pointed to the
screen and said, ".. whatever that means."
The things that happen!
Arlen
···
On Sat, Apr 19, 2008 at 8:55 PM, James Tucker <jftucker@gmail.com> wrote:
* James Tucker <jftucker@gmail.com> [2008-04-19 19:55:45 +0900]:
Hi,
I'm afraid the problem is the same: you can't interact with the program
after data has been read. any function like getch() will try to read
input
from the file to which stdin was redirected instead of your console.
You can check if you are getting data from a pipe by asking
$stdin.tty? and act accordingly.
See http://p.ramaze.net/1144 for a short example.
* James Tucker <jftucker@gmail.com> [2008-04-19 19:55:45 +0900]:
Hi,
I'm afraid the problem is the same: you can't interact with the program
after data has been read. any function like getch() will try to read
input
from the file to which stdin was redirected instead of your console.
You can check if you are getting data from a pipe by asking
$stdin.tty? and act accordingly.
See http://p.ramaze.net/1144 for a short example.