I want to execute a python script through java. I used below sample code for that. the problem is when I execute python script through commandline it save logs in to log_test.log file. but when I execute from java logs doesn't write in to the log file I'm using python 3.7 and java 1.8
Python script
import logging
logger = logging.getLogger('log_test')
logger.setLevel(logging.INFO)
fh = logging.FileHandler('log_test.log')
fh.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)
logger.info('info message')
Java code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.script.ScriptException;
public class Main {
public static void main(String[] args) throws ScriptException, IOException {
Process p = Runtime.getRuntime().exec("python ./log_test.py");
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
System.out.println("output");
String s = null;
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
}
}