Created
April 25, 2018 23:01
-
-
Save jtpaasch/79b05cd90d9cbbe00a222d120bb5afec to your computer and use it in GitHub Desktop.
A simple shell executor (OCaml)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let int_of_status s = | |
| match s with | |
| | Unix.WEXITED n -> n | |
| | Unix.WSIGNALED n -> n | |
| | Unix.WSTOPPED n -> n | |
| let psshell ?exe:(exe="/bin/sh") cmd = | |
| match Unix.fork() with | |
| | 0 -> Unix.execvp exe [| exe; "-c"; cmd |] | |
| | child_pid -> child_pid | |
| let main () = | |
| let pid = psshell "ls -la" in | |
| let pid', s = Unix.waitpid [] pid in | |
| Printf.printf "Child %d exit code: %d\n" pid' (int_of_status s) | |
| let () = Unix.handle_unix_error main () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment