[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Non exclusive file access

bino_oetomo

4/19/2007 10:08:00 AM

Dear All.

I'm trying to play with LCD4Linux
There is fascility from LCD4Linux that let it to read to a file, and refresh
the LCD with the content of file being read.

For a dirty trial , I use a Curse driver for LCD4Linux display.
It emulate 4 line LCD
I made 4 file , each intended for each line of the LCD

Next , I wrote simple BASH script below :

---START----
#!/bin/sh
a=0
b=0
while true
do
a=$(($a+1))
b=$(($b+1))
f="/mnt/ramdisk0/line"$a
echo $b >$f
if [ "$a" -eq 4 ]
then
a=0
fi
done

----STOP----

Let the script run.
While the script run .. I open 2nd console
And from that last console I run lcd4linux ... and find that it work just
like what I want.
LCD4Linux read the file .. and display the content perfectly.

Next ..
I tried to do it with ruby :

---Start----
irb
irb(main):001:0> my_file = File.new("/mnt/ramdisk0/line3", modestring="a+")
=> #<File:/mnt/ramdisk0/line3>
irb(main):002:0> my_file.flock(File::LOCK_UN)
=> 0
irb(main):003:0>
irb(main):004:0* my_file.puts "write it"
=> nil
----Stop---

The LCD4Linux can not read the file .. so it can not display the content to
LCD.

But, when I try :

irb(main):005:0> exit

And back to my main Shell ... LCD4Linux can read the file and display the
content.

2 Question :
1. How to make rubby to do shared file access ?
2. the file.puts command always write to the end of the file, How to make
ruby just overide the content of the file with it's output ?
(just like bash ==> echo "something" >./thisfile )

Sincerely
-bino-


1 Answer

Phillip Gawlowski

4/19/2007 10:50:00 AM

0

bino_oetomo wrote:
>
> ---Start----
> irb
> irb(main):001:0> my_file = File.new("/mnt/ramdisk0/line3", modestring="a+")
my_file = File.open("/mnt/ramdisk0/line3", "w")

> 2. the file.puts command always write to the end of the file, How to make
> ruby just overide the content of the file with it's output ?
> (just like bash ==> echo "something" >./thisfile )

The mode "a+" appends to a file, "w" overwrites an existing file, or
creates a new file.
See here:
http://www.zenspider.com/Languages/Ruby/QuickR...


--
Phillip "CynicalRyan" Gawlowski
http://cynicalryan....
http://clothred.rub...

Rule of Open-Source Programming #13:

Your first release can always be improved upon.