python程序:testpj.py
#coding:utf-8
import sys
print sys.argv[1]
java程序:Testpj.java
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Testpj{
public static void main(String[] args)throws Exception {
Process pr = Runtime.getRuntime().exec("python testpj.py 123");
//獲取python文件運行后的輸出
BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
? ? ?}
in.close();
pr.waitFor();
System.out.println("sucecss!");
? ?}
}
運行結果:
MacBook-Air:Downloads huangyong$ java Testpj
123
sucecss!
文件地址: