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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -