k3s/vendor/github.com/k3s-io/go-powershell/backend/local.go

39 lines
949 B
Go
Raw Normal View History

2019-09-05 18:55:53 +00:00
// Copyright (c) 2017 Gorillalabs. All rights reserved.
package backend
import (
"io"
"os/exec"
"github.com/pkg/errors"
2019-09-05 18:55:53 +00:00
)
type Local struct{}
func (b *Local) StartProcess(cmd string, args ...string) (Waiter, io.Writer, io.Reader, io.Reader, error) {
command := exec.Command(cmd, args...)
stdin, err := command.StdinPipe()
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "Could not get hold of the PowerShell's stdin stream")
2019-09-05 18:55:53 +00:00
}
stdout, err := command.StdoutPipe()
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "Could not get hold of the PowerShell's stdout stream")
2019-09-05 18:55:53 +00:00
}
stderr, err := command.StderrPipe()
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "Could not get hold of the PowerShell's stderr stream")
2019-09-05 18:55:53 +00:00
}
err = command.Start()
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "Could not spawn PowerShell process")
2019-09-05 18:55:53 +00:00
}
return command, stdin, stdout, stderr, nil
}