feature: added 'ExecuteAndGetOutputC' to process_execution

This commit is contained in:
amorozov 2024-06-21 18:23:54 +03:00
parent be72ffec43
commit f8094df331

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 {