Fix stderr log
This commit is contained in:
parent
096cad8701
commit
e04154b235
@ -378,7 +378,11 @@ func (q System) Command(user, cmd string) (output string, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
session.Stderr = session.Stdout
|
|
||||||
|
stderr, err := session.StderrPipe()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
err = session.Start(cmd)
|
err = session.Start(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -395,6 +399,17 @@ func (q System) Command(user, cmd string) (output string, err error) {
|
|||||||
output = strings.TrimSuffix(output, "\n")
|
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()
|
err = session.Wait()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user