I have next method:
public void callPython() throws IOException {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("python -c \"from test import read_and_show; read_and_show()\" src/main/python");
BufferedReader bfr = new BufferedReader(new InputStreamReader(pr.getInputStream()));
BufferedReader bfre = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String outputStr = "";
while ((outputStr = bfr.readLine()) != null) {
System.out.println(outputStr);
}
while ((outputStr = bfre.readLine()) != null) {
System.out.println(outputStr);
}
}
in python file next code:
import os
from stat import *
def read_and_show():
print('worked!')
when i call this in terminal all worked correctly (before i cd to this directory):
MacBook-Pro-Nikita-2:python NG$ python -c "from test import read_and_show; read_and_show()"
worked!
when i run this code in my java code he return error:
File "<string>", line 1
"from
^
SyntaxError: EOL while scanning string literal
What i make wrong?
P.S.: i need run python method/class/file for read, parse and show graphical data. but for this need when java run python single method (def)