Function in env compiler

exec

fn exec(string program, Vec<string> argv) -> Result<int, EnvError>
Import
use env::{exec};
Source: compiler/src/builtin_docs/env.hy

Runs program with the arguments argv and waits for it to finish.

There is no shell: program is looked up on PATH (unless it is a path) and argv excludes the program name. The child inherits this process’s working directory, environment and standard streams. Returns Ok(exit_code), or Err(EnvError::ExecFailed) if the program cannot be started or was killed by a signal. Needs --allow-exec; without the grant the program does not compile (error E0406).

Parameters#

NameType
programstring
argvVec<string>

Returns#

Result<int, EnvError>

Examples#

use env::{exec};
use tests::assert;
let argv: Vec<string> = Vec::from(["-c", "exit 3"]);
let code = match exec("sh", argv) {
    Result::Ok(c) => c,
    Result::Err(_) => -1,
};
assert!(code == 3);

See also#

  • args: Returns the program’s command-line arguments, starting with the program name.
  • var: Returns the value of the environment variable name.
  • set_var: Sets the environment variable name to value for this process.
  • remove_var: Removes the environment variable name from this process.
  • cwd: Returns the current working directory as an absolute path.
  • set_cwd: Changes the current working directory of the whole process.
  • exit: Ends the process at once with exit status code.
↑ ↓ navigate ↵ open