The Go language calls methods of other programs and gets their output

  • 2020-05-24 05:42:15
  • OfStack

This example shows how the Go language can call other programs and get their output. Share with you for your reference. The specific implementation method is as follows:

package main
import (
    "exec" // "os/exec" in go1
    "fmt"
)
func main(){
    cmd := exec.Command("ls", "-l")
    buf, err := cmd.Output()
    fmt.Printf("%s\n%s",buf,err)
}

I hope this article has been helpful to your programming of Go language.


Related articles: