title: Run python script from java as subprocess
body: <p>I'm trying to execute python code (live from the console, not just opening a single file).</p>
  
  <pre class="lang-java prettyprint-override"><code>ProcessBuilder builder = new ProcessBuilder("python");
  Process process = builder.start();
  new Thread(() -&gt; {
      try {
          process.waitFor();
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
  }).start();
  new Thread(() -&gt; {
      String line;
      final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
      // Ignore line, or do something with it
      while (true) try {
          if ((line = reader.readLine()) == null) break;
          else System.out.println(line);
      } catch (IOException e) {
          e.printStackTrace();
      }
  }).start();
  
  final PrintWriter writer = new PrintWriter(new OutputStreamWriter(process.getOutputStream()));
  writer.println("1");
  writer.println("2 * 2");
  </code></pre>
  
  <p>I tried this code, but after trying to push the following expressions <code>1</code> and <code>2*2</code>, I don't get a response (evaluation of my expressions).</p>
  
  <p>Does anyone know what the issue is?</p>