|
View:
New views
8 Messages
—
Rating Filter:
Alert me
|
|
|
"ocaml_beginners"::[] file gets deleted on subsequent program executionsI'm having a strange problem. My program deletes files created by a previous
invocation even though I'm changing the file name! My program is roughly the following: let open_out_safe = open_out_gen [Open_wronly; Open_creat; Open_excl; Open_text] 0o666 (* this is similar to open_out but does not overwrite the file if it exists *) Then I do: let cout = open_out "a.txt" ... do some calculations and print to cout ... let _ = close_out cout Now, running the program creates a file called a.txt. Then I change the script so that the file name is "b.txt". Recompile the script, and re-run it: b.txt gets created correctly, but to my surprise a.txt gets deleted! I tried several times. The problem does not occur if I use the standard open_out instead. What is going on? [Non-text portions of this message have been removed] |
|
|
Re: "ocaml_beginners"::[] file gets deleted on subsequent program executionsActually, it seems the behavior is the same with open_out.
On Mon, Jun 30, 2008 at 7:24 PM, Ashish Agarwal <agarwal1975@...> wrote: > I'm having a strange problem. My program deletes files created by a > previous > invocation even though I'm changing the file name! My program is roughly > the > following: > let open_out_safe = open_out_gen [Open_wronly; Open_creat; Open_excl; > Open_text] 0o666 > (* this is similar to open_out but does not overwrite the file if it exists > *) > > Then I do: > > let cout = open_out "a.txt" > ... do some calculations and print to cout ... > let _ = close_out cout > > Now, running the program creates a file called a.txt. Then I change the > script so that the file name is "b.txt". Recompile the script, and re-run > it: b.txt gets created correctly, but to my surprise a.txt gets deleted! I > tried several times. The problem does not occur if I use the standard > open_out instead. What is going on? > > [Non-text portions of this message have been removed] > > > [Non-text portions of this message have been removed] |
|
|
Re: "ocaml_beginners"::[] file gets deleted on subsequent program executionsAshish Agarwal wrote:
> > let cout = open_out "a.txt" > > ... do some calculations and print to cout ... > > let _ = close_out cout Hmm.. tricky. 1) Are you running this from an ocaml interactive session, compiling it with ocamlc, or compliling it with ocamlopt? 2) Are you using any sort of helper scripts to run your ocaml code that might be messing with the output files? |
|
|
Re: "ocaml_beginners"::[] file gets deleted on subsequent program executionsHello,
Zitat von Ashish Agarwal <agarwal1975@...>: > I'm having a strange problem. My program deletes files created by a > previous > invocation even though I'm changing the file name! My program is > roughly the > following: What does "roughly" mean? Can you show the whole code? > let open_out_safe = open_out_gen [Open_wronly; Open_creat; Open_excl; > Open_text] 0o666 > (* this is similar to open_out but does not overwrite the file if it > exists > *) > > Then I do: > > let cout = open_out "a.txt" > ... do some calculations and print to cout ... > let _ = close_out cout [...] This looks like problems must occur somehow ;-) Bette code the following way: let _ = cout = open_out "a.txt" in (* do something *) close_out cout From your email text it seems that you have defined cout at the compilation-unit's toplevel. And that you also do the calculations and printings on the toplevel of the compilation unit. Better do it like I wrote above. Ciao, Oliver |
|
|
Re: "ocaml_beginners"::[] file gets deleted on subsequent program executionsOn Mon, Jun 30, 2008 at 07:24:10PM -0400, Ashish Agarwal wrote:
> I'm having a strange problem. My program deletes files created by a previous > invocation even though I'm changing the file name! My program is roughly the > following: > let open_out_safe = open_out_gen [Open_wronly; Open_creat; Open_excl; > Open_text] 0o666 OCaml doesn't do anything very different from C programs. I suggest that you 'strace' your program to see what actual system call it is making (ie. to open(2)) and then look at the manpage for open(2). Rich. -- Richard Jones Red Hat |
|
|
Re: "ocaml_beginners"::[] file gets deleted on subsequent program executions> Are you running this from an ocaml interactive session, compiling it
> with ocamlc, or compliling it with ocamlopt? I've tried compiling to native and byte code. Same results. > Are you using any sort of helper scripts > What does "roughly" mean? Can you show the whole code? Actually, I just reproduced the problem with the following minimal program: --- prog.ml --- let cout = open_out "a.txt" let _ = output_string cout "hello"; close_out cout Rewriting the code as below gives the same problems: --- prog2.ml --- let _ = let cout = open_out "a.txt" in output_string cout "hello"; close_out cout This is only happening on a RedHat Enterprise Linux system. I do not have the problem on my Mac OS X. > I suggest that you 'strace' your program Thanks, I have never done that but I will look into it. On Tue, Jul 1, 2008 at 4:43 AM, Richard Jones <rich@...> wrote: > On Mon, Jun 30, 2008 at 07:24:10PM -0400, Ashish Agarwal wrote: > > I'm having a strange problem. My program deletes files created by a > previous > > invocation even though I'm changing the file name! My program is roughly > the > > following: > > let open_out_safe = open_out_gen [Open_wronly; Open_creat; Open_excl; > > Open_text] 0o666 > > OCaml doesn't do anything very different from C programs. I suggest > that you 'strace' your program to see what actual system call it is > making (ie. to open(2)) and then look at the manpage for open(2). > > Rich. > > -- > Richard Jones > Red Hat > > > [Non-text portions of this message have been removed] |
|
|
Re: "ocaml_beginners"::[] file gets deleted on subsequent program executionsHello,
Zitat von Ashish Agarwal <agarwal1975@...>: > > Are you running this from an ocaml interactive session, compiling > it > > with ocamlc, or compliling it with ocamlopt? > > I've tried compiling to native and byte code. Same results. > > > Are you using any sort of helper scripts > > What does "roughly" mean? Can you show the whole code? > Actually, I just reproduced the problem with the following minimal > program: > > --- prog.ml --- > let cout = open_out "a.txt" > let _ = > output_string cout "hello"; > close_out cout > > > Rewriting the code as below gives the same problems: > > --- prog2.ml --- > let _ = > let cout = open_out "a.txt" in > output_string cout "hello"; > close_out cout Well... both programs use normal open_out. The special stuff you mentioned in your first mail is not here now... so you threw it out, or maybe never had it inside your first code. Overwriting without any erors/exceptions is normal behaviour, so I don't know what you do expect. It seems you eat a bread and want that it tastes like pizza. I would assume, there is a difference in taste. But maybe I missed something and you can elaborate more on this. > > This is only happening on a RedHat Enterprise Linux system. I do not > have > the problem on my Mac OS X. What problem do you have? I mean: what problems do you have with the above code, and did you really compiled the above code on those systems you mentioned? Ciao, Oliver |
|
|
Re: "ocaml_beginners"::[] file gets deleted on subsequent program executionsSorry for wasting everyone's time... there was some file syncing utility
running that kept deleting files behind me. On Tue, Jul 1, 2008 at 7:35 PM, Oliver Bandel <oliver@...> wrote: > Hello, > > Zitat von Ashish Agarwal <agarwal1975@... <agarwal1975%40gmail.com> > >: > > > > Are you running this from an ocaml interactive session, compiling > > it > > > with ocamlc, or compliling it with ocamlopt? > > > > I've tried compiling to native and byte code. Same results. > > > > > Are you using any sort of helper scripts > > > What does "roughly" mean? Can you show the whole code? > > Actually, I just reproduced the problem with the following minimal > > program: > > > > --- prog.ml --- > > let cout = open_out "a.txt" > > let _ = > > output_string cout "hello"; > > close_out cout > > > > > > Rewriting the code as below gives the same problems: > > > > --- prog2.ml --- > > let _ = > > let cout = open_out "a.txt" in > > output_string cout "hello"; > > close_out cout > > Well... both programs use normal open_out. > The special stuff you mentioned in your first mail > is not here now... so you threw it out, or maybe never had it inside > your first code. > > Overwriting without any erors/exceptions is normal behaviour, > so I don't know what you do expect. > > It seems you eat a bread and want that it tastes like pizza. > I would assume, there is a difference in taste. But maybe I missed > something > and you can elaborate more on this. > > > > > This is only happening on a RedHat Enterprise Linux system. I do not > > have > > the problem on my Mac OS X. > > What problem do you have? > > I mean: what problems do you have with the above code, and did you > really compiled the above code on those systems you mentioned? > > Ciao, > Oliver > > > [Non-text portions of this message have been removed] |
| Free Forum Powered by Nabble | Forum Help |