run_subprocess/
run_subprocess.rs

1use std::process::Command;
2use utf8_supported::CommandUtf8Ext;
3
4pub fn main() {
5    let mut cmd = Command::new(std::env::args().nth(1).expect("No command provided"));
6
7    #[cfg(windows)]
8    let handle = utf8_supported::set_console_utf8().unwrap_or_default();
9
10    let support = utf8_supported::utf8_supported();
11    if support == utf8_supported::Utf8Support::UTF8 {
12        println!("run_subprocess: UTF-8 supported ({support:?})");
13    } else {
14        #[cfg(unix)]
15        {
16            println!("run_subprocess: Setting C locale ({support:?})");
17            cmd.set_c_locale();
18        }
19    }
20    let output = cmd.output().expect("failed to run command");
21    println!("{}", String::from_utf8_lossy(&output.stdout));
22}