Sy11
(Sy)
1
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
···
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?
--
suffering increases your inner strength. also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama
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?
Use mode 'a' instead of 'a+' in File.open
Yoann
Sy11
(Sy)
4
That worked like a charm, thanks!
···
On 6/6/06, Yoann Guillot <john-rubytalk@ofjj.net> wrote:
Use mode 'a' instead of 'a+' in File.open
Sy11
(Sy)
5
Just a quick thanks.. this pointed me in the right direction for some
of the more advanced uses of 'open'. It'll come in handy. =)
···
On 6/5/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
harp:~ > ruby -e' open("file", File::WRONLY|File::APPEND|File::CREAT, 0666){|f| f.puts "string2"} '