Executing External Commands

Function: list exec (list command[, str input])

Asynchronously executes the specified external executable, optionally sending input. Returns the process return code, output and error. If the programmer is not a wizard, then E_PERM is raised.

The first argument must be a list of strings, or E_INVARG is raised. The first string is the path to the executable and is required. The rest are command line arguments passed to the executable.

The path to the executable may not start with a slash (/) or dot-dot (..), and it may not contain slash-dot (/.) or dot-slash (./), or E_INVARG is raised. If the specified executable does not exist or is not a regular file, E_INVARG is raised.

If the string input is present, it is written to standard input of the executing process.

When the process exits, it returns a list of the form:

{code, output, error}

code is the integer process exit status or return code. output and error are strings of data that were written to the standard output and error of the process.

The specified command is executed asynchronously. The function suspends the current task and allows other tasks to run until the command finishes. Tasks suspended this way can be killed with kill_task().

The strings, input, output and error are all MOO binary strings.

All external executables must reside in the executables directory.

exec({"cat", "-?"})                                   ⇒   {1, "", "cat: illegal option -- ?~0Ausage: cat [-benstuv] [file ...]~0A"}
exec({"cat"}, "foo")                                  ⇒   {0, "foo", ""}
exec({"echo", "one", "two"})                          ⇒   {0, "one two~0A", ""}