Re: Std. IO streams in Ruby

Jatin Kumar
2010-08-01T20:09:37Z

Frederick Cheung wrote:
> On Aug 1, 7:29�pm, Jatin Kumar
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:
>> textfield where he/she can enter the input, and the program continues
to
>>
>> In short, how can I get control of stdin, so that whenever the stdin
>> waits for some user input, i get to know that it is waiting for the
user
>> input and then i can show the user a text field and get the user input
>> to be passed in the stdin stream.
>> Let me know if there''s a doubt in the question.
>
> Well in a plain old ruby script IO.popen allows you to run a command
> and gets you the command stdin/stdout (and open3/popen3 gets you
> stderr too).
>
> Controlling this interactively via a webapp is much more tricky. A
> single http request only has a single response, so you''d have to
break
> this up across multiple requests. There''s no guarantee that the
next
> request from the user will go to the same rails instance, so figuring
> out what do do with the IO objects connecting you to the command being
> run is tricky enough.
>
> One possible way out is to have some long running daemon process that
> does that actual running of the command and have your rails actions
> communicate with that. If just polling for whether the command is
> waiting for input isn''t acceptable then you might need to look at
> comet and that sort of thing. If you can restrict yourself to specific
> browsers, the new html5 websockets stuff might be interesting too
>
> Fred

@Fred :-I have been looking over the internet for a solution but never
got a real answer. Thanks for your help.
My web app allows the user to run code in the browser window itself, so
do i really need to do polling for that? I mean is there any better
solution? If not, how can I use your approach. I have never tried
something like that before, so a little confused. Can you explain it
using a little code snippet? That would really help me out.
Also, the responses would be through AJAX. The user code will be sent
back to server through an AJAX call, the file created for the code and
then the response back to the browser(the output of file executed) in an
AJAX call. So, that guarantee that next request will go to same rails
instance, won''t that vanish away or not? Could be elaborate a little
bit
on this too.
--
Posted via http://www.ruby-forum.com/.