• Ephera@lemmy.ml
      link
      fedilink
      English
      arrow-up
      3
      ·
      7 hours ago

      One of the simplest tricks is that you can throw down a function, which you can call with a command like e.g. this: run("cat /etc/os-release | grep NAME")
      by constructing a Command like so:

      Command::new("sh")
          .arg("-c")
          .arg(command) //the string passed as parameter
      

      There’s proper libraries to make running commands even easier and more robust, but if you don’t want to pull in a library, that’s really easy to write out ad-hoc and gets you 95% of the way there, with shell piping and everything.