[erlang-questions] File IO

Vlad12 <>
Fri May 16 22:06:01 CEST 2008


Sorry for the confusion, it turns out that adding file:close solved the
porblem on the toy problem i used as a "test". I added file:close to my real
program and it didnt work.. then I relaized that part was never executed.

Thank you for your comments.


Vlad12 wrote:
> 
> 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 <> 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 <> 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
>>>> 
>>>> 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
>> 
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>> 
>> 
> 
> 

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




More information about the erlang-questions mailing list