[Rails] Re: interactive web app

Inge Jørgensen
Wed, 05 Jul 2006 14:03:08 -0000

User wrote:
> I have 3 concerns:
>
> 1)By sending output of program to a text file, you mean modify the
> binary right?
>
No. If it outputs to stdout, you could easily redirect it to a file. Try
typing "Foo.exe > myfile.txt". This overwrites myfiles.txt with the
output from Foo.exe. If you want do append to the file instead of
overwriting, do "Foo.exe >> myfile.txt". Works exactly the same
on *nix

> 2)And if I were to modify the binary and send all outputs to a text file
> and not stdout, how do I specifically read just the last lines that were
> added, instead of rereading the whole file from the top.
>
If you need just the last line, you could read the file into a string,
and do:
filecontents = get_file_contents_somehow()
lastline = filecontents.split( /\n/ ).last

you could create an array of lines with
lines = filecontents.split( /\n/ )
> 3) How do I do an update every few seconds using AJAX and how would I
> update it without redisplaying the entire file, but rather just the new
> lines that were added to the file.
>
Look at the prototype helpers, they''re documented in the rails
api.
> thanks
>
> Inge J?rgensen wrote:
>
>> That''s not a problem. Send the output of the program to a text
file
>> (works on both *nix and windows). Create a rails action that parses the
>> file and outputs either the last line or the entire file (depending on
>> what you''re trying to do). Then, create an ajax updater in the
view that
>> updates a div every few seconds with the output of the action.
>>
>
>
>