* Stdout
@ 2000-01-12 9:50 c-job
2000-01-17 16:34 ` Stdout Xavier Leroy
0 siblings, 1 reply; 2+ messages in thread
From: c-job @ 2000-01-12 9:50 UTC (permalink / raw)
To: caml-list
Bonjour,
Je cherche a detourner l'association des flots de texte stdout de son
peripherique habituel vers un fichier.
La fonction freopen permet cela en C.
Existe t il une telle fonction en Caml, s agit il de la fonction :
val descr_of_out_channel : out_channel -> file_descr ?
merci
a bientot ?
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Stdout
2000-01-12 9:50 Stdout c-job
@ 2000-01-17 16:34 ` Xavier Leroy
0 siblings, 0 replies; 2+ messages in thread
From: Xavier Leroy @ 2000-01-17 16:34 UTC (permalink / raw)
To: c-job, caml-list
[Summary: Caml equivalent of freopen() in ANSI C? ]
> Je cherche a detourner l'association des flots de texte stdout de son
> peripherique habituel vers un fichier.
> La fonction freopen permet cela en C.
> Existe t il une telle fonction en Caml, s agit il de la fonction :
> val descr_of_out_channel : out_channel -> file_descr ?
Vous êtes sur la bonne voie. On peut en effet émuler le freopen de C
à l'aide de la fonction Unix.dup2 d'OCaml. Voici un exemple:
let reopen_out outchan filename =
flush outchan;
let fd1 = Unix.descr_of_out_channel outchan in
let fd2 =
Unix.openfile filename [Unix.O_WRONLY; Unix.O_CREAT; Unix.O_TRUNC] 0o666 in
Unix.dup2 fd2 fd1;
Unix.close fd2
let _ =
print_string "Some text on stdout\n";
reopen_out stdout "/tmp/foo";
print_string "Some text on /tmp/foo\n"
Ceci dit, il est souvent plus souple d'écrire son code Caml de manière
à ce qu'il prenne le canal de sortie en argument, ou le trouve dans
une référence globale:
let current_output = ref stdout
let myfunction () =
... output_string !current_output s ...
- Xavier Leroy
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2000-01-17 16:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-12 9:50 Stdout c-job
2000-01-17 16:34 ` Stdout Xavier Leroy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox