interfaces.go 679 B

123456789101112131415161718192021222324252627
  1. package executor
  2. import "os/exec"
  3. // SyncExecutor executes commands with os/exec
  4. type SyncExecutor interface {
  5. RunSync(string, ...string) ([]byte, error)
  6. }
  7. // AsyncExecutor starts process and stops it
  8. type AsyncExecutor interface {
  9. StartAsync(string, ...string) (*exec.Cmd, error)
  10. StopAsync(*exec.Cmd) error
  11. }
  12. func RunSync(executor SyncExecutor, command string, args ...string) ([]byte, error) {
  13. return executor.RunSync(command, args...)
  14. }
  15. func RunAsync(runner AsyncExecutor, command string, args ...string) (*exec.Cmd, error) {
  16. return runner.StartAsync(command, args...)
  17. }
  18. func StopAsync(stopper AsyncExecutor, prc *exec.Cmd) error {
  19. return stopper.StopAsync(prc)
  20. }