I'm trying to compile a Python code using Java. The Python code opens a csv file and saves the data to an other csv file.
import os
from stat import*
import csv
data = []
with open('Example.csv') as f:
reader = csv.reader(f, delimiter = ',')
for row in reader:
data.append(row)
f = open("Clearprint.csv","w")
f.truncate()
f.close()
with open('Clearprint.csv','w',newline='') as fp:
a = csv.writer(fp,delimiter = ',')
a.writerows(data)
The Python code works as it should but when I try to compile it through Java nothing happens.
class test1{
public static void main(String[] args) throws IOException {
String pythonScriptPath = "C:/Masters/Python/helloPython.py";
String[] cmd = new String[2];
cmd[0] = "C:/Python33/python.exe";
cmd[1] = pythonScriptPath;
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(cmd);
BufferedReader bfr = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = "";
while((line = bfr.readLine()) != null) {
System.out.println(line);
}
}
}
In the case of the Python code only having a print command everything works fine so it might be something to do with me using a csv. Note that I don't need anything to be returned to Java from Python or be sent to Python. I just want Java to start the Python code and let Python do everything else.
Thank You