forked from allan2/dotenvy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
22 lines (19 loc) · 808 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//! This example modifies the existing environment.
//!
//! This makes environment varaibles from available to subprocesses, e.g., a Python script.
use dotenvy::{EnvLoader, EnvSequence};
use std::{env, error, fs, io, process::Command};
fn main() -> Result<(), Box<dyn error::Error>> {
// to override, set sequence to `EnvThenInput` or `InputOnly`
let loader = EnvLoader::with_path("../env-example").sequence(EnvSequence::InputThenEnv);
unsafe { loader.load_and_modify() }?;
println!("HOST={}", env::var("HOST")?);
print_host_py()?;
Ok(())
}
fn print_host_py() -> io::Result<()> {
let script = fs::read_to_string("print_host.py")?;
let output = Command::new("python3").arg("-c").arg(script).output()?;
print!("{}", String::from_utf8_lossy(&output.stdout));
Ok(())
}