Rust processes: Difference between revisions
From wikinotes
(Created page with " = Documentation = <blockquote> {| class="wikitable" |- | <code>std::env</code> (process environment) || https://doc.rust-lang.org/std/env/index.html |- |} </blockquote><!-- Documentation --> = Current Process = <blockquote> <syntaxhighlight lang="rust"> use std::env; let args: Vec<String> = env::args().collect(); </syntaxhighlight> </blockquote><!-- Current Process -->") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
|- | |- | ||
| <code>std::env</code> (process environment) || https://doc.rust-lang.org/std/env/index.html | | <code>std::env</code> (process environment) || https://doc.rust-lang.org/std/env/index.html | ||
|- | |||
| <code>std::process</code> (manage processes) || https://doc.rust-lang.org/std/process/index.html | |||
|- | |- | ||
|} | |} | ||
Line 11: | 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(); | 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