1

How can I print out a command's output?

let mut telnet_scan_command = Command::new("telnet");
telnet_scan_command.arg("0.0.0.0");

match telnet_scan_command.output() {
    Ok(o) => {
        println!("{}", String::from_utf8_unchecked(o.stdout))
    }
    Err(e) => {
        println!("Something Went wrong Log: {} ", e)
    }
    

The program runs perfectly fine but the output should be:

Trying 0.0.0.0...
telnet: Unable to connect to remote host: Connection refused

The actual output is:

Trying 0.0.0.0...

How can I get the rest of the output?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • 1
    Errors are usually printed to `stderr`, so you'd need to get that – Herohtar Feb 04 '22 at 20:19
  • Thank you it worked biut now the telnet command says "Name or service not known" same with ping like it dosen't detect it (sorry i"m kinda new ) –  Feb 04 '22 at 21:09
  • Duplicate of [How do I invoke a system command and capture its output?](https://stackoverflow.com/questions/21011330/how-do-i-invoke-a-system-command-and-capture-its-output) – Herohtar Feb 04 '22 at 21:13
  • That's a separate issue, so you'd need to ask a new question and provide details about your setup and what you're trying to connect to; however, it's just a problem with connecting with telnet and not related to programming, so not on topic for StackOverflow. – Herohtar Feb 04 '22 at 21:14

0 Answers0