title: How does Runtime.exec work?
body: <p>I use the following lines of code to run a python script:</p>
  
  <pre><code>    Runtime rt = Runtime.getRuntime();  
      String command = PYTHON + " " + "foo.py";
      try {
          System.out.println("Python Command: " + command);
          rt.exec(command);
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Previously it was enough to set <code>PYTHON ="python";</code> however after setting up Anaconda3 again, this did no longer work, though entering above command via command line did work. </p>
  
  <p>Java threw the following error code: <code>java.io.IOException: Cannot run program "python": CreateProcess error=2, The system cannot find the file specified</code></p>
  
  <p>However I found out, that Java was completely happy, if I gave it the full path to the python.exe inside Anaconda3 and everything worked magically. </p>
  
  <p>This got me curious now, how <code>Runetime.exec</code> really works, when and how environment variables are used/accepted properly as I find the just described behaviour rather strange. </p>
  
  <p>As always any constructive comment/answer makes me happy. </p>
  
  <p>There are also other users on stackoverflow, who had the same problem, however no conclusive answers were provided. I refer to.</p>
  
  <p><a href="https://stackoverflow.com/questions/44845041/run-python-script-from-java-code?noredirect=1&amp;lq=1">Run Python script from java code</a></p>
  
  <p><a href="https://stackoverflow.com/questions/10097491/call-and-receive-output-from-python-script-in-java?noredirect=1&amp;lq=1">Call and receive output from Python script in Java?</a></p>