On Tue, 6 Jun 2006, Sy Ali wrote:

> File.open(file, 'a+') won't work when the file is not readable.
>
> However, in a shell I can append a string using
> echo string >> file
>
> Am I forced to use exec + echo to append content, or is there a way to
> append a string to a file using ruby code.. without opening the file?


   harp:~ > rm file


   harp:~ > touch file


   harp:~ > chmod 200 file


   harp:~ > strace sh -c 'echo string >> file' 2>&1|grep open|tail -1
   open("file", O_WRONLY|O_APPEND|O_CREAT|O_LARGEFILE, 0666) = 3


   harp:~ > ruby -e'  open("file", File::WRONLY|File::APPEND|File::CREAT, 0666){|f| f.puts "string2"}  '


   harp:~ > chmod 600 file


   harp:~ > cat file
   string
   string2


-a
-- 
suffering increases your inner strength.  also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama