1
0
Fork 0
mirror of https://github.com/vbatts/talks.git synced 2024-12-27 09:06:30 +00:00
talks/2013/03-golang-learning-lunch/6-inheritance/main.go

41 lines
594 B
Go
Raw Permalink Normal View History

2016-12-05 15:44:45 +00:00
package main
import (
"log"
"os"
"os/exec"
"time"
)
type Job struct {
Command string
*log.Logger
}
func NewJob(cmd string) *Job {
return &Job{ cmd, log.New(os.Stderr, "[Job] ", log.Ldate)}
}
func (j *Job) Run() ([]byte, error) {
j.Printf("Running [%s] ...", j.Command)
out, err := exec.Command(j.Command).Output()
if (err != nil) {
j.Fatal(err)
return nil, err
}
j.Printf("Command returned [%s]", out)
return out, nil
}
func main() {
job := NewJob("uptime")
job.Run()
for i := 0; i < 10; i++ {
job.Run()
time.Sleep(1 * time.Second)
}
}