1
0

Fix stderr log

This commit is contained in:
dump_stack() 2023-04-26 14:35:20 +00:00
parent 096cad8701
commit e04154b235
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC

View File

@ -378,7 +378,11 @@ func (q System) Command(user, cmd string) (output string, err error) {
if err != nil {
return
}
session.Stderr = session.Stdout
stderr, err := session.StderrPipe()
if err != nil {
return
}
err = session.Start(cmd)
if err != nil {
@ -395,6 +399,17 @@ func (q System) Command(user, cmd string) (output string, err error) {
output = strings.TrimSuffix(output, "\n")
}()
go func() {
scanner := bufio.NewScanner(stderr)
for scanner.Scan() {
m := scanner.Text()
output += m + "\n"
// Note: it prints stderr as stdout
flog.Trace().Str("stdout", m).Msg("")
}
output = strings.TrimSuffix(output, "\n")
}()
err = session.Wait()
return
}