Function in env compiler

set_cwd

fn set_cwd(string path) -> Result<unit, EnvError>
Import
use env::{set_cwd};
Source: compiler/src/builtin_docs/env.hy

Changes the current working directory of the whole process.

Relative paths opened later, and programs started with exec, use the new directory. Returns Err(EnvError::Other) if path does not exist or is not an accessible directory. Needs --allow-env.

Parameters#

NameType
pathstring

Returns#

Result<unit, EnvError>

Examples#

use env::{cwd, set_cwd};
use tests::assert;
let before = match cwd() { Result::Ok(d) => d, Result::Err(_) => "/" };
assert!(match set_cwd("/tmp") { Result::Ok(_) => true, Result::Err(_) => false });
let _ = set_cwd(before);

See also#

  • env::exec
  • 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.
  • exit: Ends the process at once with exit status code.
↑ ↓ navigate ↵ open