Rust processes: Difference between revisions
From wikinotes
(One intermediate revision by the same user not shown) | |||
Line 13: | Line 13: | ||
= Current Process = | = Current Process = | ||
<blockquote> | <blockquote> | ||
General | |||
<syntaxhighlight lang="rust"> | <syntaxhighlight lang="rust"> | ||
use std::env; | use std::env; | ||
let args: Vec<String> = env::args().collect(); // commandline arguments | let args: Vec<String> = env::args().collect(); // commandline arguments | ||
std::env::set_current_dir() // change cwd | |||
</syntaxhighlight> | |||
Environment | |||
<syntaxhighlight lang="rust"> | |||
use std::env; | |||
std::env::set_var() // set environment variable | |||
std::env::var() // get environment variable | |||
std::env::remove_var() // remove environment variable | |||
</syntaxhighlight> | |||
Exit Process | |||
<syntaxhighlight lang="rust"> | |||
use std::process; | |||
std::process::abort() // exit process un-cleanly, no destructors called | |||
std::process::exit() // exit with returncode | |||
std::process::id() // process's pid | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Current Process --> | </blockquote><!-- Current Process --> |
Latest revision as of 02:16, 9 February 2023
Documentation
std::env
(process environment)https://doc.rust-lang.org/std/env/index.html std::process
(manage processes)https://doc.rust-lang.org/std/process/index.html
Current Process
General
use std::env; let args: Vec<String> = env::args().collect(); // commandline arguments std::env::set_current_dir() // change cwdEnvironment
use std::env; std::env::set_var() // set environment variable std::env::var() // get environment variable std::env::remove_var() // remove environment variableExit Process
use std::process; std::process::abort() // exit process un-cleanly, no destructors called std::process::exit() // exit with returncode std::process::id() // process's pid