CmdResult
#struct CmdResultThe result of a command.
| Name | Type | Description |
|---|---|---|
code | int = 0 | The exit code; zero means success, 128 plus the signal number when a signal ended it, and -1 when the program could not start. |
out | str = "" | The standard output, newlines included; it stops at the first zero byte. |
err | str = "" | The error output. |
import os.shell
func main:
mut args := Vector {} as Vector<str>
defer args.Free()
args.Push("-n")
args.Push("hello")
r := shell.Run("echo", args)
println r.code, "[" + r.out + "]"
r2 := shell.Exec("echo one two three")
println r2.code, "[" + r2.out + "]"
mut args2 := Vector {} as Vector<str>
defer args2.Free()
args2.Push("-c")
args2.Push("echo oops >&2; exit 3")
r3 := shell.Run("sh", args2)
println r3.code, "[" + r3.err + "]"
println shell.System("true"), shell.System("false") != 0
end0 [hello] 0 [one two three ] 3 [oops ] 0 true