You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 2331 Reporter: administrator Status: closed Resolution: not a bug Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
The following code works under 3.06, but fails with
Sys_error("Bad file descriptor") unter 3.07+2.
If I don't Unix.close n_stdin at (* X *) it seems to work in 3.07, too.
Is this change in semantics intended or not?
let _ =
let oc = open_out "input.txt" in
output_string oc "TESTTESTTEST\n";
close_out oc;
let o_stdin = Unix.dup Unix.stdin in
let ic = Unix.open_process_in ("cat input.txt") in
let n_stdin = Unix.descr_of_in_channel ic in
Unix.dup2 n_stdin Unix.stdin; Unix.close n_stdin; (* X )
let l = read_line () in
print_endline ("1 Read string: " ^ l);
let excode= Unix.close_process_in ic in
Unix.dup2 o_stdin Unix.stdin; Unix.close o_stdin;
( Unix.sleep 1000; *)
print_endline ("2 Read string: " ^ l)
The text was updated successfully, but these errors were encountered:
The following code works under 3.06, but fails with
Sys_error("Bad file descriptor") unter 3.07+2.
If I don't Unix.close n_stdin at (* X *) it seems to work in 3.07, too.
Is this change in semantics intended or not?
Yes. "close_process_in" calls "close_in". In 3.06, "close_in" ignores
any error reported by the "close" system call. In 3.07+2, these errors
are not ignored but reported by raising an exception.
let _ =
let oc = open_out "input.txt" in
output_string oc "TESTTESTTEST\n";
close_out oc;
let o_stdin = Unix.dup Unix.stdin in
let ic = Unix.open_process_in ("cat input.txt") in
let n_stdin = Unix.descr_of_in_channel ic in
Unix.dup2 n_stdin Unix.stdin; Unix.close n_stdin; (* X )
let l = read_line () in
print_endline ("1 Read string: " ^ l);
let excode= Unix.close_process_in ic in
Unix.dup2 o_stdin Unix.stdin; Unix.close o_stdin;
( Unix.sleep 1000; *)
print_endline ("2 Read string: " ^ l)
You are first closing the file descriptor of ic, then trying to close ic
itself. That's a mistake.
Original bug ID: 2331
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Full_Name: Florian Hars
Version: 3.07+2
OS: Linux
Submission from: grisu.bik-gmbh.de (217.110.154.194)
The following code works under 3.06, but fails with
Sys_error("Bad file descriptor") unter 3.07+2.
If I don't Unix.close n_stdin at (* X *) it seems to work in 3.07, too.
Is this change in semantics intended or not?
let _ =
let oc = open_out "input.txt" in
output_string oc "TESTTESTTEST\n";
close_out oc;
let o_stdin = Unix.dup Unix.stdin in
let ic = Unix.open_process_in ("cat input.txt") in
let n_stdin = Unix.descr_of_in_channel ic in
Unix.dup2 n_stdin Unix.stdin; Unix.close n_stdin; (* X )
let l = read_line () in
print_endline ("1 Read string: " ^ l);
let excode= Unix.close_process_in ic in
Unix.dup2 o_stdin Unix.stdin; Unix.close o_stdin;
( Unix.sleep 1000; *)
print_endline ("2 Read string: " ^ l)
The text was updated successfully, but these errors were encountered: