0

I'm writing a small script in Rust and I need to get the user who is running it. I thought to retrieve the user using a simple process, something like this:

let output = Command::new("whoami")
             .output();
let user = output.stdout;

I don't know how to convert user into a string so that I can use it for println!.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Christopher Loen
  • 177
  • 1
  • 2
  • 7
  • 1
    Please note that by executing `whoami` you sacrifice cross-platform compatibility. There appears to be a [`user` crate](https://crates.io/crates/user) exactly for this purpose. Looks pretty inactive to me, though :/ – Lukas Kalbertodt Aug 24 '16 at 13:53
  • Thanks, I'll see what I can do with that crate – Christopher Loen Aug 24 '16 at 18:47

0 Answers0