Slide 26 of 37
Terminal and processes
Running another program
proc main(): void {
result := hive.term.exec("hostname", [], "")
if result is Result.Ok(output) {
echo "this machine is called: {output}"
} else if result is Result.Error(why) {
echo "could not run hostname: {why.message}"
}
}
Asking about the terminal itself
proc main(): void {
echo hive.term.isTerminal()
echo hive.term.args()
}
hive.term is line-oriented terminal I/O: print writes to stdout, status writes to stderr — what a program is doing, as against what it was asked for — isTerminal says whether standard error is a person or a pipe, and read/readSecret block for a line of input, the second with the terminal's echo turned off. args() reads the command line, and exit(code) ends the program on the spot. Running another program is two calls apart by who is talking to the terminal: exec hands back everything the command wrote and turns a nonzero exit into a Result.Error, while attach gives the command this program's own terminal and answers with its exit status. Neither ever touches a shell, so nothing in an argument can be read as one.