raz / test / libc / ExecC.raz

15 lines · 578 B · raw · history · last change ac9d3e89

1(* Sys.exec over the C library: this program replaced by sh, with an
2 fd it keeps, at its own number, and one it doesn't; sh's output and
3 status are its. *)
4module ExecC;
5import Sys;
6
7proc main*: INT;
8begin
9 if (Sys.dupTo(Sys.stdout, 7) # 7) or (Sys.dupTo(Sys.stdout, 8) # 8) then return 1; end;
10 if (Sys.keepOnExec(7, false) # 0) or (Sys.keepOnExec(8, false) # 0) then return 1; end;
11 return Sys.exec({path: "sh", env: ["X=replaced"], more: [7],
12 args: ["sh", "-c", "echo $X >&7; { echo kept >&8; } 2>/dev/null || echo closed; exit 5"]});
13end;
14
15end ExecC.