execute1 [#golang] 소스코드에서 커맨드 실행하기 golang 안에서 git clone 또는 git pull을 하는 등 직접 커맨드를 실행해야 하는 경우가 많다. 이번 포스팅에선 golang 안에서 직접 커맨드를 실행하는 방법에 대해서 알아보자 예를들면 워킹 디렉토리(working directory) /test/workspace 안에서 ls -a 를 실행하는 커맨드를 입력한다고 하면 아래와 같은 방식으로 사용할 수 있다. import ( "os/exec" ) cmd := exec.Command("ls", "-a") cmd.Dir = "/test/workspace" output, err := cmd.Output() if err != nil { fmt.Println(err) } else { fmt.Println(string(output)) } 지원하지 않는.. 2020. 3. 26. 이전 1 다음