[erlang-questions] File IO

Vlad12 vsarpe@REDACTED
Fri May 16 21:52:55 CEST 2008


Adding file:close(WriteDescr) did not solve the problem.

The file gets created but nothing get written. Strange



Tuncer Ayaz wrote:
> 
> On Fri, May 16, 2008 at 8:42 PM, Gleb Peregud <gleber.p@REDACTED> wrote:
>> I haven't checked it myself, but i think you sould close file when
>> done writing (to force erlang/OS to flush IO). Add
>> file:close(WriteDescr). at the end of the function
> 
> Adding file:close is good but even without file:close
> the file gets written, it's only delayed a bit and
> the file may be locked.
> 
> Am I wrong to remember/assume that file io is done
> async'ly and possibly via message passing internally?
> 
>> On 5/16/08, Vlad12 <vsarpe@REDACTED> wrote:
>>>
>>> Hi, I am trying to create an erlang program that takes a binary trace
>>> file
>>> and converts it into normal text.
>>>
>>> My question is, how can i write a bunch of terms to a file. Here is how
>>> my
>>> code looks like, but using different terms (in string representation)
>>> and
>>> this compiles, runs, but produces an empty file. Am I missing something
>>> important?
>>>
>>> -module(test).
>>> -export([write/1]).
>>> -import(lists,[foreach/2]).
>>>
>>> write(WriteFile) ->
>>>    {ok, WriteDescr} = file:open(WriteFile, [raw, write]),
>>>    Terms = ["one","two","three","four","five"],
>>>    Writer=fun(Term) -> file:write(WriteDescr, Term) end,
>>>    lists:foreach(Writer, Terms).
>>>
>>> Vlad.
>>> --
>>> View this message in context:
>>> http://www.nabble.com/File-IO-tp17281272p17281272.html
>>> Sent from the Erlang Questions mailing list archive at Nabble.com.
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>>
>>
>>
>> --
>> Gleb Peregud
>> http://gleber.pl/
>>
>> Every minute is to be grasped.
>> Time waits for nobody.
>> -- Inscription on a Zen Gong
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 
> 

-- 
View this message in context: http://www.nabble.com/File-IO-tp17281272p17282943.html
Sent from the Erlang Questions mailing list archive at Nabble.com.




More information about the erlang-questions mailing list