feature: added 'ExecuteAndGetOutputC' to process_execution

master
amorozov 2024-06-21 18:23:54 +03:00
parent be72ffec43
commit f8094df331
1 changed files with 11 additions and 1 deletions

View File

@ -3,7 +3,17 @@ package process_execution
import "os/exec"
func ExecuteAndGetOutput(command string, args ...string) (string, error) {
outputBytes, err := exec.Command(command, args...).CombinedOutput()
return ExecuteAndGetOutputC(nil, command, args...)
}
func ExecuteAndGetOutputC(cfg func(*exec.Cmd), command string, args ...string) (string, error) {
process := exec.Command(command, args...)
if cfg != nil {
cfg(process)
}
outputBytes, err := process.CombinedOutput()
outputString := ""
if outputBytes != nil && len(outputBytes) > 0 {