2020-06-16 11:42:51 +02:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2022-08-05 13:08:19 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
2020-06-16 11:42:51 +02:00
|
|
|
"os/exec"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// errCopyStdout and errCopyStderr are filled after the command execution after Wait() terminates
|
2020-06-16 11:42:51 +02:00
|
|
|
type execution struct {
|
|
|
|
cmd *exec.Cmd
|
|
|
|
wg sync.WaitGroup
|
|
|
|
errCopyStdout error
|
|
|
|
errCopyStderr error
|
2022-08-05 13:08:19 +02:00
|
|
|
ul *log.URLLogger
|
2020-06-16 11:42:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (execution *execution) Kill() error {
|
|
|
|
return execution.cmd.Process.Kill()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (execution *execution) Wait() error {
|
|
|
|
execution.wg.Wait()
|
2022-08-05 13:08:19 +02:00
|
|
|
execution.ul.WriteURLsLogToJSON()
|
2020-06-16 11:42:51 +02:00
|
|
|
return execution.cmd.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Execution references a background process which is started by RunExecutableInBackground
|
|
|
|
type Execution interface {
|
|
|
|
Kill() error
|
|
|
|
Wait() error
|
|
|
|
}
|