Rust processes: Difference between revisions

From wikinotes
 
(2 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();  // 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 cwd

Environment

use std::env;

std::env::set_var()      // set environment variable
std::env::var()          // get environment variable
std::env::remove_var()   // remove environment variable

Exit 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