2014-06-11 5 views
-2

내가 내가받을 컴파일 할 때 파이썬 스크립트는 자바

Runtime r = Runtime.getRuntime(); 
Process p = r.exec("cmd /c python ps.py sender-ip=10.10.10.10"); 

를 호출하는 자바 프로그램을 만든 파이썬은 (클래스, 인터페이스 또는 열거 예상)를 호출 오류 :

call_py.java:1: error: class, interface, or enum expected 
Runtime r = Runtime.getRuntime(); 
^ 
call_py.java:2: error: class, interface, or enum expected 
Process p = r.exec("cmd /c python ps.py sender-ip=10.10.10.10"); 
^ 
2 errors 

모두 자바 프로그램 와 python 스크립트가 같은 디렉토리에 있다면 어떻게 해결할 수 있습니까?

+0

왜 downvotes을 ??? – Glowie

답변

6

파이썬에서는 코드를 실행할 수 있지만 자바에서는 쉽지 않습니다.

코드를 클래스 내부의 메서드 안에 넣어야합니다.

다음과 같은 내용으로 "PythonCallTest.java"라는 이름의 파일을 생성하십시오 :

public class PythonCallTest { 

    public static void main(String[] args) { 
     Runtime r = Runtime.getRuntime(); 
     Process p = r.exec("cmd /c python ps.py sender-ip=10.10.10.10"); 
    } 
}