
// CallPython.java
// Andrew Davison, ad@coe.psu.ac.th, July 2023

/* Execute a Python file from Java.

  Usage:
     > javac CallPython
     > java CallPython [ <Python fnm> ]
   e.g.
     > java CallPython
     > java CallPython Hearts.py
     > java CallPython spirals.py

*/

import java.io.*;
import java.util.*;
import java.util.stream.*;


public class CallPython
{
  public static void main(String[] args)
  {
    String fnm = null;
    if (args.length != 1) {
      System.out.println("Usage: java CallPython [<Python fnm>]\n");

      // create a temporary Python file
      String[] lines = { "print('Hello World')" };
      fnm  = PyUtils.writeToTemp(lines);
    }
    else
      fnm = args[0];

    int exitValue = PyUtils.exec("python", fnm);
  }  // end of main()

} // end of CallPython class
