0

I am calling a python file from my script and passing a Hindi word. But the file is unable to read it. The code:

cmd = ['java', '-jar','jython-standalone-2.5.3.jar','pythonfile.py',word]

proc = subprocess.Popen(cmd, stderr = STDOUT, stdout = subprocess.PIPE, shell=True)

I tried to read the argument from the pythonfile:

print(sys.argv[1])

But I get ??? as the output.

When I pass a non-Hindi word, e.g. "word", I get the correct output.

Any clue as to why this is happening?

Thanks in advance.

RAM
  • 2,413
  • 1
  • 21
  • 33
gvenugopal
  • 21
  • 1
  • 5
  • 1
    I don't know Jython, but I suspect that you need to explicitly encode the word that you're passing to "pythonfile.py" in the `cmd` list, eg `word.encode('UTF8')`. Then in "pythonfile.py" you should decode those bytes to a Unicode string. – PM 2Ring Aug 19 '18 at 12:29
  • Thanks, tried that, but even after decoding, I'm getting the same string that I sent in the form of bytes: b'\xe0\xa4\xaa\xe0\xa5\x81\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4\xe0\xa4\x95\xe0\xa5\x87\xe0\xa4\x82' – gvenugopal Aug 19 '18 at 16:23
  • This is probably happening because it does not allow passing of bytes as an argument, so I have to typecast it to str and then send. – gvenugopal Aug 19 '18 at 16:43
  • I think you should post a [mcve] that demonstrates your problem. Also mention the Python version you're using. I know Jython is currently equivalent to CPython 2.7, but I suspect that your Python code which calls the Jython script is running on some version of Python 3. And Python 2 & 3 have major differences in string handling, especially in regards to Unicode. FWIW, the UTF-8 b-string in your previous comment decodes to "पसतक". – PM 2Ring Aug 19 '18 at 17:03
  • Yes, the version could be the problem because the code that works without calling jython is not working when I'm calling the file using jython. Will try out a few more experiments and get back, thanks. – gvenugopal Aug 20 '18 at 03:52

0 Answers0