c - Can not read utmpx file in go -
package main import ( "os" "fmt" ) func main() { fd, err := os.open("/var/run/utmpx") fmt.println(fd, err) var data []byte len, err := fd.read(data) fmt.println(len, err) }
&{0xc42000a240} nil
0 nil
there no error, no data.
this path /var/run/utmpx
read system header file.
how path another question
system: macos el capiton, go version go1.8 darwin/amd64
**my final goal read file go struct.**this file contains system users infomation.
can ? keep trying...
you can use ioutil.readfile
function this:
package main import ( "fmt" "io/ioutil" ) func main() { fd, err := ioutil.readfile("/var/run/utmpx") fmt.println(string(fd), err) }
the problem in original code read data
0 bytes long. since reader interface reads reads len(data)
, reads nothing. more on that: https://golang.org/pkg/io/#reader
Comments
Post a Comment