title: Java, Caused by: java.io.IOException: error=2, No such file or directory
body: <pre><code>java.io.IOException: Cannot run program "yarn": error=2, No such file or directory
      at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
      at java.lang.Runtime.exec(Runtime.java:620)
      at java.lang.Runtime.exec(Runtime.java:450)
      at java.lang.Runtime.exec(Runtime.java:347)
      at com.Main.main(Main.java:32)
  </code></pre>
  
  <p>Hi there, I have a weird problem when execute a command using Java. I used the following code to run a command, if I run <code>mkdir testFolder</code>, the program run successful, but if I changed the command like <code>yarn -v</code>
  then error happen.</p>
  
  <pre><code>try {
      Process process = Runtime.getRuntime().exec("yarn -v");//, null, new File("/Users/macos/Desktop/TestProj/"));
  } catch (IOException ex) {
      ex.printStackTrace();
  }
  </code></pre>
  
  <p>P/s: In debug mode: IntelliJ could run above code, but Netbeans failed.</p>
  
  <p>In production mode (jar file): IntelliJ failed too.</p>
  
  <p><strong>Edit 2:</strong></p>
  
  <pre><code>  MACs-MacBook-Pro:~ macos$ which pwd
      /bin/pwd
      MACs-MacBook-Pro:~ macos$ which mkdir
      /bin/mkdir
      MACs-MacBook-Pro:~ macos$ which java
      /usr/bin/java
      MACs-MacBook-Pro:~ macos$ which yarn
      /usr/local/bin/yarn
  </code></pre>
  
  <p>I found that if I run a command that is in <code>/bin</code> or <code>/usr/bin</code>, the code run ok (pwd, mkdir, java -version ...), but yarn is in <code>/usr/local/bin/</code>, so it didn't work, and I still don't know how to fix.</p>