title: Check if a command is in PATH/executable as process
body: <p>I want to execute an external program via <code>std::process::Command::spawn</code>. Furthermore I want to know the reason why spawning the process failed: is it because the given program name doesn't exist/is not in PATH or because of some different error?</p>
  
  <p>Example code of what I want to achieve:</p>
  
  <pre><code>match Command::new("rustc").spawn() {
      Ok(_) =&gt; println!("Was spawned :)"),
      Err(e) =&gt; {
          if /* ??? */ {
              println!("`rustc` was not found! Check your PATH!")
          } else {
              println!("Some strange error occurred :(");
          }
      }, 
  }
  </code></pre>
  
  <p>When I try to execute a program that isn't on my system, I get:</p>
  
  <pre><code>Error { repr: Os { code: 2, message: "No such file or directory" } }
  </code></pre>
  
  <p>But I don't want to rely on that. Is there a way to determine if a program exists in PATH?</p>