Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
GOで外部コマンドを呼び出すにはどうすればよいですか? 外部プログラムを呼び出して、実行が完了するまで待機する必要があります。次のステートメントが実行される前に。
package main import ( "fmt" "os/exec" "log" ) func main() { cmd := exec.Command("ls", "-ltr") out, err := cmd.CombinedOutput() if err != nil { log.Fatal(err) } fmt.Printf("%s\n", out) }
オンラインで試す