move Run with stderr output to its own command
This commit is contained in:
parent
167de85fe9
commit
5ee76f5ece
1 changed files with 25 additions and 2 deletions
|
@ -23,17 +23,40 @@ func Run(binary string, args ...string) ([]string, error) {
|
||||||
|
|
||||||
// Read the output
|
// Read the output
|
||||||
output, _ := io.ReadAll(&stdout)
|
output, _ := io.ReadAll(&stdout)
|
||||||
outerr, _ := io.ReadAll(&stderr)
|
|
||||||
|
|
||||||
// Get the output
|
// Get the output
|
||||||
outputs := []string{}
|
outputs := []string{}
|
||||||
outputs = append(outputs, string(output))
|
outputs = append(outputs, string(output))
|
||||||
outputs = append(outputs, string(outerr))
|
|
||||||
|
|
||||||
// Return our list of items
|
// Return our list of items
|
||||||
return outputs, err
|
return outputs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function is just like command.Run() but also returns STDERR
|
||||||
|
func RunErr(binary string, args ...string) ([]string, []string, error) {
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
|
||||||
|
// Configure the ls-iommu c--ommand
|
||||||
|
cmd := exec.Command(binary, args...)
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
cmd.Stdout = &stdout
|
||||||
|
|
||||||
|
// Execute the command
|
||||||
|
err := cmd.Run()
|
||||||
|
|
||||||
|
// Read the output
|
||||||
|
output, _ := io.ReadAll(&stdout)
|
||||||
|
outerr, _ := io.ReadAll(&stderr)
|
||||||
|
|
||||||
|
// Get the output
|
||||||
|
var outputs, outerrs []string
|
||||||
|
outputs = append(outputs, string(output))
|
||||||
|
outerrs = append(outerrs, string(outerr))
|
||||||
|
|
||||||
|
// Return our list of items
|
||||||
|
return outputs, outerrs, err
|
||||||
|
}
|
||||||
|
|
||||||
// This functions runs the command "sudo -Sk -- echo", this forces sudo
|
// This functions runs the command "sudo -Sk -- echo", this forces sudo
|
||||||
// to re-authenticate and lets us enter the password to STDIN
|
// to re-authenticate and lets us enter the password to STDIN
|
||||||
// giving us the ability to run sudo commands
|
// giving us the ability to run sudo commands
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue