Initial Linux distro detection

This commit is contained in:
Lea Anthony
2018-12-16 20:16:40 +11:00
parent 04c64c1bea
commit 6edd941c1a
2 changed files with 57 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package cmd
import (
"bytes"
"os/exec"
"path/filepath"
)
@@ -41,3 +42,25 @@ func (p *ProgramHelper) FindProgram(programName string) *Program {
Path: path,
}
}
func (p *Program) GetFullPathToBinary() (string, error) {
result := filepath.Join(p.Path, p.Name)
return filepath.Abs(result)
}
// Run will execute the program with the given parameters
// Returns stdout + stderr as strings and an error if one occured
func (p *Program) Run(vars ...string) (stdout, stderr string, err error) {
command, err := p.GetFullPathToBinary()
if err != nil {
return "", "", err
}
cmd := exec.Command(command, vars...)
var stdo, stde bytes.Buffer
cmd.Stdout = &stdo
cmd.Stderr = &stde
err = cmd.Run()
stdout = string(stdo.Bytes())
stderr = string(stde.Bytes())
return
}