get system release in go

You can use the os package in Go to get the operating system's release information using the uname command. Here's an example:

main.go
package main

import (
    "fmt"
    "os/exec"
)

func main() {
    cmd := exec.Command("uname", "-r")
    release, err := cmd.Output()

    if err != nil {
        fmt.Println(err)
        return
    }

    fmt.Println("OS Release:", string(release))
}
254 chars
19 lines

The exec package provides the Command function which allows you to specify a command to be executed along with any arguments. In this case, we're executing the uname -r command which prints the kernel release information. We then use the Output function of the Cmd structure to run the command and capture its output. Finally, we print the resulting release string to the console.

related categories

gistlibby LogSnag