0

I need to pass a java string value (a path to a pdf file) to a function in the Jython interpreter, that is os.startfile(filename, "print") (where filename is the string). So i tried to write it like this:

 import org.python.util.PythonInterpreter;

 PythonInterpreter interpreter = new PythonInterpreter();
 interpreter.set("filename", fileDaStampare);
 interpreter.exec("import os");
 interpreter.exec("os.startfile(filename, \"print\")");

but it returns me this error when I execute tha java program:

console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0. Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'startfile'

What can I do to execute this little piece of code in the Python interpreter?

Marco Am
  • 23
  • 6
  • Have you tried the suggestions in this [question](https://stackoverflow.com/questions/30443537/how-do-i-fix-unsupportedcharsetexception-in-eclipse-kepler-luna-with-jython-pyde)? – user7217806 Dec 02 '19 at 12:05
  • @user7217806: I tried and the first error just disappeared, but the second one persists: Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'startfile' – Marco Am Dec 02 '19 at 13:03
  • `os.startfile` does not exist in Jython. See this old but unresolved issue: https://bugs.jython.org/issue1100. – mzjn Dec 02 '19 at 16:39
  • I tried the solution described in https://stackoverflow.com/questions/27195594/python-silent-print-pdf-to-specific-printer/51325336 but even win32api and win32print return this: File "", line 1, in NameError: name 'win32api' is not defined – Marco Am Dec 04 '19 at 10:50

0 Answers0