2014-06-11 3 views

답변

0

실행 파일로 python progam을 호출 할 수 있습니다.

이렇게하는 장난감 파이썬 프로그램은 다음과 같습니다

import java.io.*; 
class Interact { 

    static public void main(String[] args) throws IOException { 
    Process p = Runtime.getRuntime().exec("python3 python_program.py arg1 arg2"); 
    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); 
    String line; 
    while ((line = in.readLine()) != null) { 
     System.out.println(line); 
    } 
    } 
} 

python_program.py 경우 결과가 더에 물론

my args are ['arg1', 'arg2'] 

을해야

import sys 
if __name__ == "__main__" 
    print("my args are",sys.argv[1:]) 

다음 당신이 stderr를 읽고 리턴 코드 등을 확인해야하는 완전한 프로그램.

+1

이것은 스프링 배치의 파이썬 코드 실행을 다루지 않습니다. –