ExecutePy.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ExecutePy {
public static void main(String[] args) {
try {
String shell = "run.sh";
Process process = Runtime.getRuntime().exec(shell);
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
int result = process.waitFor();
System.out.println("执行结果:" + result);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
字符串shell中run.sh是自己定义的shell脚本
run.sh
#/bin/bash
python test.py