1

thank you for helping I'm trying to write and read characters from a Java process to a Python process. While the other way(print from python and get it in the Java process) is working fine, the Python process seems not to get the output of the Java process.

Here are the codes i'm trying to use:

JAVA

A class to manage python process

class Pyexe {
Process pypr;
BufferedReader pybuffreader;
BufferedWriter pybuffwriter;
public Pyexe(String filecmd) throws IOException{
    pypr=Runtime.getRuntime().exec("py "+filecmd);
    pybuffreader=new BufferedReader(new InputStreamReader(pypr.getInputStream()));
    pybuffwriter=new BufferedWriter(new OutputStreamWriter(pypr.getOutputStream()));

}
public void Pyend(){
    this.pypr.destroy();
}

}

Main: launch python process, send a string, then get the python output

public class JavaLearn{
public static void main(String[]argv)throws IOException{

    Pyexe pyexe=new Pyexe("c:/pathtofile/testpy.py");
    pyexe.pybuffwriter.write("Have a nice day\n");
    String line=pyexe.pybuffreader.readLine();
    System.out.println(line);}


    }

PYTHON A simple script : get input(), print it lowercase

line=input()
print(line.lower())

When launched, the python process just wait indefinetely for the input. If i only use:

print("Something".lower())

and use the Bufferedreader it's fine, the Java process get the output from Python.

Any idea of what is going on? Thank you in advance

NyuB
  • 93
  • 7

0 Answers0