* [Caml-list] copy file
@ 2001-04-26 16:54 Mark Scheffer
2001-04-26 17:10 ` Alan Schmitt
2001-04-26 17:25 ` Georges Brun-Cottan
0 siblings, 2 replies; 3+ messages in thread
From: Mark Scheffer @ 2001-04-26 16:54 UTC (permalink / raw)
To: caml-list
Hello Caml users,
I'm new to caml and have compiled this cp.ml file on my windows system using
"ocamlc -o cp.exe cp.ml".
However, I do not get any response when trying to use it. Is there an error
in the file?
Thanks in advance for any help that might get this to work.
- Mark.
---
(* File copier.ml *)
let copy inch outch =
(* inch and outch are supposed to be opened channels *)
try (* actual copying *)
while true
do output_char outch (input_char inch)
done
with End_of_file -> (* Normal termination *)
raise End_of_file
| Sys_error msg -> (* Abnormal termination *)
prerr_endline msg;
raise (Failure "cp")
| _ -> (* Unknown exception, maybe interruption? *)
prerr_endline "Unknown error while copying";
raise (Failure "cp")
;;
let cp f1 f2 =
(* Opening channels, f1 firsty, then f2 *)
let inch =
try open_in f1
with Sys_error msg ->
prerr_endline (f1^": "^msg);
raise (Failure "cp")
| _ -> prerr_endline ("Unknown exception while opening "^f1);
raise (Failure "cp")
in
let outch =
try open_out f2
with Sys_error msg ->
close_in inch;
prerr_endline (f2^": "^msg);
raise (Failure "cp")
| _ -> close_in inch;
prerr_endline ("Unknown exception while opening "^f2);
raise (Failure "cp")
in (* Copying and then closing *)
try copy inch outch
with End_of_file -> close_in inch; close_out outch
(* close_out flushes *)
| exc -> close_in inch; close_out outch; raise exc
;;
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] copy file
2001-04-26 16:54 [Caml-list] copy file Mark Scheffer
@ 2001-04-26 17:10 ` Alan Schmitt
2001-04-26 17:25 ` Georges Brun-Cottan
1 sibling, 0 replies; 3+ messages in thread
From: Alan Schmitt @ 2001-04-26 17:10 UTC (permalink / raw)
To: Mark Scheffer; +Cc: caml-list
Hi,
Correctly indenting the second function, you get:
let cp f1 f2 =
(* Opening channels, f1 firsty, then f2 *)
let inch =
try open_in f1
with Sys_error msg ->
prerr_endline (f1^": "^msg);
raise (Failure "cp")
| _ -> prerr_endline ("Unknown exception while opening "^f1);
raise (Failure "cp")
in
let outch =
try open_out f2
with Sys_error msg ->
close_in inch;
prerr_endline (f2^": "^msg);
raise (Failure "cp")
| _ -> close_in inch;
prerr_endline ("Unknown exception while opening "^f2);
raise (Failure "cp")
in (* Copying and then closing *)
try copy inch outch
with End_of_file -> close_in inch; close_out outch
(* close_out flushes *)
| exc -> close_in inch; close_out outch; raise exc
;;
So basically you just define a function here ... If you never call it,
nothing happens.
Alan
>Hello Caml users,
>
>I'm new to caml and have compiled this cp.ml file on my windows system using
>"ocamlc -o cp.exe cp.ml".
>However, I do not get any response when trying to use it. Is there an error
>in the file?
>
>Thanks in advance for any help that might get this to work.
>
>
>- Mark.
>
>---
>
>(* File copier.ml *)
>
>let copy inch outch =
> (* inch and outch are supposed to be opened channels *)
> try (* actual copying *)
> while true
> do output_char outch (input_char inch)
> done
> with End_of_file -> (* Normal termination *)
> raise End_of_file
> | Sys_error msg -> (* Abnormal termination *)
> prerr_endline msg;
> raise (Failure "cp")
> | _ -> (* Unknown exception, maybe interruption? *)
> prerr_endline "Unknown error while copying";
> raise (Failure "cp")
>;;
>
>
>let cp f1 f2 =
> (* Opening channels, f1 firsty, then f2 *)
> let inch =
> try open_in f1
> with Sys_error msg ->
> prerr_endline (f1^": "^msg);
> raise (Failure "cp")
> | _ -> prerr_endline ("Unknown exception while opening "^f1);
> raise (Failure "cp")
>in
>let outch =
> try open_out f2
> with Sys_error msg ->
> close_in inch;
> prerr_endline (f2^": "^msg);
> raise (Failure "cp")
> | _ -> close_in inch;
> prerr_endline ("Unknown exception while opening "^f2);
> raise (Failure "cp")
>in (* Copying and then closing *)
> try copy inch outch
> with End_of_file -> close_in inch; close_out outch
> (* close_out flushes *)
> | exc -> close_in inch; close_out outch; raise exc
>
>;;
>
>
>-------------------
>To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
--
The hacker: someone who figured things out and made something cool happen.
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] copy file
2001-04-26 16:54 [Caml-list] copy file Mark Scheffer
2001-04-26 17:10 ` Alan Schmitt
@ 2001-04-26 17:25 ` Georges Brun-Cottan
1 sibling, 0 replies; 3+ messages in thread
From: Georges Brun-Cottan @ 2001-04-26 17:25 UTC (permalink / raw)
To: zax; +Cc: caml-list
> I'm new to caml and have compiled this cp.ml file on my windows system using
> "ocamlc -o cp.exe cp.ml".
> However, I do not get any response when trying to use it. Is there an error
> in the file?
Mark, your program works fine. But you simply forgot to invoke your
function ;-)
Add the following line at the end of your program and it will do what
you expect:
let _ = cp Sys.argv.(1) Sys.argv.(2)
or
let _ = cp "foo" "bar"
(to copy an existing file "foo" to a file "bar".)
BTW, zax@chello.nl returns a permanent mail error. You should fix
that.
Best,
-- Georges
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-04-26 17:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-26 16:54 [Caml-list] copy file Mark Scheffer
2001-04-26 17:10 ` Alan Schmitt
2001-04-26 17:25 ` Georges Brun-Cottan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox