raz / test / run / Exec.raz

14 lines · 554 B · raw · history · last change ac9d3e89

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