47 lines
1.4 KiB
Java
47 lines
1.4 KiB
Java
package com.ytlk.fusion;
|
||
|
||
import com.alibaba.fastjson.JSONObject;
|
||
|
||
import java.io.*;
|
||
|
||
/**
|
||
* @className:test
|
||
* @author:cwchen
|
||
* @date:2025-04-16-9:06
|
||
* @version:1.0
|
||
* @description:
|
||
*/
|
||
public class test {
|
||
|
||
|
||
public static void main(String[] args) {
|
||
try {
|
||
// 创建ProcessBuilder
|
||
String python = "D:\\miniconda3\\envs\\ocr\\python.exe";
|
||
String pythonScript = new File("C:\\Users\\10488\\Desktop\\ocr-release\\main.py").getAbsolutePath();
|
||
String param1 = "C:\\Users\\10488\\Desktop\\1.pdf";
|
||
String param2 = "C:\\Users\\10488\\Desktop\\test (2)";
|
||
ProcessBuilder pb = new ProcessBuilder(
|
||
python,
|
||
pythonScript,
|
||
"--input", param1,
|
||
"--output", param2
|
||
);
|
||
pb.directory(new File("C:\\Users\\10488\\Desktop\\ocr-release"));
|
||
Process p = pb.start();
|
||
// 读取输出
|
||
BufferedReader reader = new BufferedReader(
|
||
new InputStreamReader(p.getInputStream()));
|
||
String line;
|
||
while ((line = reader.readLine()) != null) {
|
||
System.out.println(line);
|
||
}
|
||
// 等待进程结束
|
||
int exitCode = p.waitFor();
|
||
System.out.println("Python脚本执行完毕,退出码: " + exitCode);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
}
|