process.popen with Japanese args => UTF8 JAVA

Cameron Simpson cs at
Sun Mar 9 10:09:26 CET 2014

On 09Mar2014 16:52, Jun Tanaka <tnajun at> wrote:
> I have tried to process.popen to run java program with Japanese language.
> is compiled with utf8
> '日本語' below means Japanese in Japanese.
> but it does not work. Anyone who knows this matter well. Please help.
> Jun
> >>>>>>>>python code>>>>>>>>>>>>>
> sentence = '日本語'
> filename = 'japanese'
> java_file = 'test'
> cmd = "java {0} {1} {2}".format(java_file, sentence, filename)
> proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
> stderr=subprocess.STDOUT)
> >>>>>>>>python code end>>>>>>>>>>>>>>>>>>>>>>

Echoing Ben, what errors do you get? And what expected?

But examining your program, it is possible that any error messages
are being concealed. Details below.

Firstly, I am surprised that the sentence comes before the java
file "test". Try swapping them.

Also, if you're doing this in a UNIX system of some kind, and therefore
your "cmd" variable is actually a shell comment, turn on tracing.
Change this:

  cmd = "java {0} {1} {2}"

to this:

  cmd = "set -x; java {0} {1} {2}"

It will show you the command the shell executes.

Finally, why do you have:


Normally you would leave stderr alone, so that error messages show
on your terminal. In particular, the shell tracing an any error
messages from your java command go to stderr, and grabbing stderr
like that may well be concealing any useful error messages you ought
to be seeing. I would be inclined to simple get rid of your stderr=
parameter and see what shows up.

Cameron Simpson <cs at>

Processes are like potatoes.    - NCR device driver manual

More information about the Python-list mailing list