ref: 155c90d05b745a22fceb60c44ff0a69d3a6466b5
parent: cad03a966cd487cf0b9bb24cb02b971337282911
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Feb 13 17:00:16 EST 2017
Add a 'run' function to libstd. It's useful, and it was missing.
--- a/lib/std/spork.myr
+++ b/lib/std/spork.myr
@@ -1,15 +1,33 @@
use "die"
+use "errno"
use "execvp"
use "fmt"
use "result"
use "syswrap"
-use "errno"
+use "wait"
pkg std =
+ const run : (cmd : byte[:][:] -> waitstatus)
const spork : (cmd : byte[:][:] -> result((pid, fd, fd), errno))
const espork : (cmd : byte[:][:] -> result((pid, fd, fd, fd), errno))
const filterfd : (fd : fd, cmd : byte[:][:] -> result(pid, errno))
;;
+
+const run = {cmd
+ var pid
+
+ pid = fork()
+ /* error */
+ if pid < 0
+ -> `Waiterror
+ elif pid == 0
+ execvp(cmd[0], cmd)
+ die("failed exec\n")
+ else
+ -> wait(pid)
+ ;;
+}
+
const spork = {cmd
var infds : fd[2], outfds : fd[2]