java调用python脚本如何获取到二进制类型返回值?

java代码:

    public void dumps(String data) {
        ClassPathResource classPathResource = new ClassPathResource("/python/dumps.py");
        try {
            String path = classPathResource.getFile().getAbsolutePath();
            String[] args = new String[] {"python", path, data};
            Process proc = Runtime.getRuntime().exec(args);
            
            BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
            in.close();
            proc.waitFor();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

python代码:

import sys
import pickle

if __name__ == '__main__':
    param = sys.argv[1]
    bin = pickle.dumps(param)
    print(bin)

输出结果为空,请教下如何获取到pickle.dumps()返回的二进制数据呢

会不会是输出流缓冲的问题,试试print(bin, flush=True)