fix goroutine call for commands with no handlers
This commit is contained in:
parent
2a59a80b11
commit
2b190eccb7
1 changed files with 31 additions and 27 deletions
58
linux/run.go
58
linux/run.go
|
@ -119,40 +119,44 @@ func (cmd *LinuxCommand) Run() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.wg.Add(3)
|
cmd.wg.Add(1)
|
||||||
|
|
||||||
go func() {
|
if len(cmd.handlers) != 0 {
|
||||||
defer cmd.wg.Done()
|
cmd.wg.Add(2)
|
||||||
scanner := bufio.NewScanner(cmd.stderr)
|
|
||||||
for scanner.Scan() {
|
go func() {
|
||||||
line := scanner.Text()
|
defer cmd.wg.Done()
|
||||||
if h, ok := cmd.handlers[EventOutput]; ok {
|
scanner := bufio.NewScanner(cmd.stderr)
|
||||||
if err := h.(func(data EventOutputData) error)(EventOutputData{
|
for scanner.Scan() {
|
||||||
Output: line,
|
line := scanner.Text()
|
||||||
CmdOptions: cmd.Options,
|
if h, ok := cmd.handlers[EventOutput]; ok {
|
||||||
}); err != nil {
|
if err := h.(func(data EventOutputData) error)(EventOutputData{
|
||||||
return
|
Output: line,
|
||||||
|
CmdOptions: cmd.Options,
|
||||||
|
}); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}()
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer cmd.wg.Done()
|
defer cmd.wg.Done()
|
||||||
|
|
||||||
scanner := bufio.NewScanner(cmd.stdout)
|
scanner := bufio.NewScanner(cmd.stdout)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
if h, ok := cmd.handlers[EventOutput]; ok {
|
if h, ok := cmd.handlers[EventOutput]; ok {
|
||||||
if err := h.(func(data EventOutputData) error)(EventOutputData{
|
if err := h.(func(data EventOutputData) error)(EventOutputData{
|
||||||
Output: line,
|
Output: line,
|
||||||
CmdOptions: cmd.Options,
|
CmdOptions: cmd.Options,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}()
|
||||||
}()
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer cmd.wg.Done()
|
defer cmd.wg.Done()
|
||||||
|
|
Loading…
Reference in a new issue