Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] copy file
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-04-26 (16:54)
From: Mark Scheffer <zax@c...>
Subject: [Caml-list] copy file
Hello Caml users,

I'm new to caml and have compiled this file on my windows system using
"ocamlc -o cp.exe".
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 *)

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)
 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")
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  Archives: