ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Golang] 파이썬 모듈 실행하기
    언어/Golang 2017. 2. 18. 13:14

    파이썬 모듈을 go자체에서 import 하는 방법은 모르겠고.. exec 패키지를 사용해 리눅스에 파이썬 모듈을 command를 날리는 형식으로 실행합니다.

    // testpython 모듈 실행 코드
    // testpython 모듈 내의 test_function()을 호출하여 반환 값을 print()하는 코드
     
    command := "import testpython; print(testpython.test_function())"
    
    // 리눅스내 파이썬 명령어 실행
    cmd := exec.Command("python3", "-c", command)
    
    out, err := cmd.CombinedOutput()
    if err != nil {
       fmt.Println(err)
    }
    // 결과출력
    fmt.Println(string(out))


    댓글