简体   繁体   English

动态将python输出日志重定向到Java GUI

[英]Redirect python output log to Java GUI dynamically

I have designed a GUI in Java using Swing. 我已经使用Swing在Java中设计了一个GUI。

Using GUI I read the location as inputs 使用GUI,我将该位置读取为输入

Using these inputs as parameter I call a Python Script from this Java Code 使用这些输入作为参数,我从此Java代码中调用Python脚本

Now, I need to display the output of the python script on GUI dynamically. 现在,我需要在GUI上动态显示python脚本的输出。 As the python script runs the output log of the script has to be displayed on the GUI area simultaneously. 随着python脚本运行,该脚本的输出日志必须同时显示在GUI区域上。

Is there anyway I can do that ? 反正我能做到吗?

Please help 请帮忙

A code would be useful, however, you could write the python script output on a file and than read that output from that file to the Java GUI. 代码很有用,但是,您可以将python脚本输出写入文件中,然后再将该输出从该文件读取到Java GUI中。

Python 蟒蛇

out_file = open("test.txt","w")
out_file.write("This Text is going to out file\nLook at it and see\n")
out_file.close()

JAVA 爪哇

File name = new File("C:/path/test.txt");

if (name.isFile()) {

    try {

        BufferedReader input = new BufferedReader(new FileReader(name));
        StringBuffer buffer = new StringBuffer();

        String text;

        while ((text = input.readLine()) != null){

             buffer.append(text + "\n");}

        input.close();
        System.out.println(buffer.toString());

    } catch (IOException ioException) {}

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM