Jython Caching Argv
Debashish <[email protected]> Sun, 12 Aug 2018 00:46:09 +0530
| Newsgroups | gmane.comp.lang.jython.user |
|---|---|
| Message-ID | <CAPj52kFW5jTZ1OnuXbvDFhQSwic-LQ_xE0cdw0zotF13na4uRw@mail.gmail.com> |
Hi,
I am trying to call a Python Script from a Spring Boot applications. There
are two issues I am facing:
(1) The Jython Standalone JAR is not detected and I am forced to supply the
local install path as "python.home" to make it work.
(2) Once I initialize the *PythonInterpreter* class, it seems it caches the
argv I supply to it as for the subsequent invocation it uses the same argv
values. I do call the close() method to do cleanup, but it doesn't help :(
Properties preprops = System.getProperties();
Properties props = new Properties();
props.put("python.home", "C:\\Dev\\Python27");
props.put("python.console.encoding", "UTF-8");
props.put("python.security.respectJavaAccessibility", "false");
props.put("python.import.site", "false");
PythonInterpreter.initialize(preprops, props, arguments);
PythonInterpreter pyInterpreter = new PythonInterpreter();
try {
resource = new ClassPathResource("mypyscript.py");
out = new ByteArrayOutputStream();
err = new ByteArrayOutputStream();
pyInterpreter.setOut(out);
pyInterpreter.setErr(err);
pyInterpreter.execfile(resource.getInputStream());
result[0] = out.toString(); // reading the output
result[1] = err.toString(); // reading any error
} catch (Exception e) {
throw new Exception(e);
} finally {
try {
if (out != null)
out.close();
if (err != null)
err.close();
pyInterpreter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Please help.
Thanks,
Deb
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Jython-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-users