'Why doesn't my rust project output anything?
my point of this program is to see if certain processes are running. My code checks with no problem, but it doesn't output anything. It creates the file, but that's it. If anyone could help I would really appreciate it. I've already spent 3 weeks on the project I'm adding this code to, and it is really frustrating af.
Code:
use sysinfo::{ProcessExt, System, SystemExt};
use std::fs::{OpenOptions, write};
use std::io::Error;
fn get_process(pid: &str) -> Result<(), Error>
{
let _log = OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open("process_list.txt")?;
let p = System::new_all();
for mut _proc in p.processes_by_exact_name(pid)
{
let is_up = _proc.name();
if is_up == "Opera"
{
write("process_list.txt", b"Opera is up")?;
//}else if is_up == "Google Chrome"{
//println!("chrome is running");
//}else if is_up == "Firefox" {
//println!("firefox is running");
}else{
write("process_list.txt", b"NOTHING IS RUNNING!!!")?;
}
}
Ok(())
}
fn main()
{
loop {
get_process("Opera").ok();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
