local.go 966 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright (c) 2017 Gorillalabs. All rights reserved.
  2. package backend
  3. import (
  4. "io"
  5. "os/exec"
  6. "github.com/juju/errors"
  7. )
  8. type Local struct{}
  9. func (b *Local) StartProcess(cmd string, args ...string) (Waiter, io.Writer, io.Reader, io.Reader, error) {
  10. command := exec.Command(cmd, args...)
  11. stdin, err := command.StdinPipe()
  12. if err != nil {
  13. return nil, nil, nil, nil, errors.Annotate(err, "Could not get hold of the PowerShell's stdin stream")
  14. }
  15. stdout, err := command.StdoutPipe()
  16. if err != nil {
  17. return nil, nil, nil, nil, errors.Annotate(err, "Could not get hold of the PowerShell's stdout stream")
  18. }
  19. stderr, err := command.StderrPipe()
  20. if err != nil {
  21. return nil, nil, nil, nil, errors.Annotate(err, "Could not get hold of the PowerShell's stderr stream")
  22. }
  23. err = command.Start()
  24. if err != nil {
  25. return nil, nil, nil, nil, errors.Annotate(err, "Could not spawn PowerShell process")
  26. }
  27. return command, stdin, stdout, stderr, nil
  28. }