1.5 KiB
| id | name | category | kind | tokens | sig | tip | order | ns | member |
|---|---|---|---|---|---|---|---|---|---|
| process-spawn | Process.spawn | process | namespace-method | Process.spawn | Process.spawn(path, args) -> int | Start a program; never blocks. | 0 | Process | spawn |
Starts the program at path with the arguments in args (a []string; the child's argv[0] is path) and returns a handle >= 0 straight away, or -1 when the program could not be started — a missing file, a file that is not executable, or all 16 handles in use.
No shell is involved, so every argument reaches the child exactly as written: spaces, quotes and $ are not interpreted. The child inherits this process's environment and working directory. On Windows the arguments are joined into one command line quoted so the child's C runtime splits it back into the same list, the path and arguments cross as UTF-8 and are converted to UTF-16, and the child is started without a console window (a GUI program is unaffected; a console program runs hidden). Use an absolute path: there is no PATH search.
On macOS the child writes to this process's standard output and error. On Windows it inherits no handles, so a console child's output goes nowhere; nothing is captured on either platform.
program Demo {
entry {
let h = Process.spawn("/bin/sh", ["-c", "exit 3"])
print(h >= 0)
}
}
See Process.poll for the exit code.