fix goroutine call for commands with no handlers

This commit is contained in:
Shane C 2024-07-11 16:34:08 -04:00
parent 2a59a80b11
commit 2b190eccb7
Signed by: shane
GPG key ID: E46B5FEA35B22FF9

View file

@ -119,40 +119,44 @@ func (cmd *LinuxCommand) Run() error {
}
}
cmd.wg.Add(3)
cmd.wg.Add(1)
go func() {
defer cmd.wg.Done()
scanner := bufio.NewScanner(cmd.stderr)
for scanner.Scan() {
line := scanner.Text()
if h, ok := cmd.handlers[EventOutput]; ok {
if err := h.(func(data EventOutputData) error)(EventOutputData{
Output: line,
CmdOptions: cmd.Options,
}); err != nil {
return
if len(cmd.handlers) != 0 {
cmd.wg.Add(2)
go func() {
defer cmd.wg.Done()
scanner := bufio.NewScanner(cmd.stderr)
for scanner.Scan() {
line := scanner.Text()
if h, ok := cmd.handlers[EventOutput]; ok {
if err := h.(func(data EventOutputData) error)(EventOutputData{
Output: line,
CmdOptions: cmd.Options,
}); err != nil {
return
}
}
}
}
}()
}()
go func() {
defer cmd.wg.Done()
go func() {
defer cmd.wg.Done()
scanner := bufio.NewScanner(cmd.stdout)
for scanner.Scan() {
line := scanner.Text()
if h, ok := cmd.handlers[EventOutput]; ok {
if err := h.(func(data EventOutputData) error)(EventOutputData{
Output: line,
CmdOptions: cmd.Options,
}); err != nil {
return
scanner := bufio.NewScanner(cmd.stdout)
for scanner.Scan() {
line := scanner.Text()
if h, ok := cmd.handlers[EventOutput]; ok {
if err := h.(func(data EventOutputData) error)(EventOutputData{
Output: line,
CmdOptions: cmd.Options,
}); err != nil {
return
}
}
}
}
}()
}()
}
go func() {
defer cmd.wg.Done()