Browse thread
[Caml-list] GC and file descriptors
-
Dustin Sallings
- David Fox
- Nicolas George
- Mikael Brockman
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Dustin Sallings <dustin@s...> |
| Subject: | Re: [Caml-list] GC and file descriptors |
> Dustin Sallings wrote:
>
>>
>> I keep ending up with somewhat awkward structures to close files
>> I've opened. Does the GC take care of any of this type of thing?
On Nov 12, 2003, at 17:18, David Fox wrote:
> I might start with this
>
> let for_process_output f cmd =
> let r = Unix.open_process_in cmd in
> let result = f r in
> Unix.close_process_in r;
> result
>
> then
>
> let tput x = for_process_output (fun r -> input r buf 0 8) ("tput " ^
> x)
>
> at which point you start thinking about exception handling...
Well, I didn't see the close_process thing, but that made things a bit
worse. My goal is to capture the output of a command with each of two
args. I currently have this:
exception SubprocessError of string;;
(* Get a string from the tput command. *)
let tput x =
let r = Unix.open_process_in ("tput " ^ x)
and buf = String.create 8 in
let len = input r buf 0 8 in
let status = Unix.close_process_in r in
begin
match status with
Unix.WEXITED(st) -> if (st != 0) then
raise (SubprocessError "Non-zero exit status");
| _ -> raise (SubprocessError "Unknown error.");
end;
String.sub buf 0 len
;;
(* The two characters we need. *)
let smso = tput "smso";;
let rmso = tput "rmso";;
This is to give me the equivalent of the following bourne shell:
smso=`tput smso`
rmso=`tput rmso`
Garbage collecting the subprocesses and file descriptors would make
this a bit more straightforward.
--
SPY My girlfriend asked me which one I like better.
pub 1024/3CAE01D5 1994/11/03 Dustin Sallings <dustin@spy.net>
| Key fingerprint = 87 02 57 08 02 D0 DA D6 C8 0F 3E 65 51 98 D8 BE
L_______________________ I hope the answer won't upset her. ____________
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners