123456789101112131415161718192021222324(* [execve] doesn't exist on Windows, so instead we do a
[Unix.create_process_env] followed by [Unix.waitpid] and finally [sys_exit].
We use [sys_exit] rather than [exit] so that [at_exit] functions are not
invoked. We don't want [at_exit] functions to be invoked to match the
behaviour of [Unix.execve] on Unix. *)externalsys_exit:int->'a="caml_sys_exit"letrestore_cwd_and_execveprogargv~env=letenv=Env.to_unixenvinletargv=Array.of_listargvinSys.chdir(Path.External.to_stringPath.External.initial_cwd);ifSys.win32thenletpid=Unix.create_process_envprogargvenvUnix.stdinUnix.stdoutUnix.stderrinmatchsnd(Unix.waitpid[]pid)with|WEXITEDn->sys_exitn|WSIGNALED_->sys_exit255|WSTOPPED_->assertfalseelse(ignore(Unix.sigprocmaskSIG_SETMASK[]:intlist);Stdlib.do_at_exit();Unix.execveprogargvenv)