blob: 75ca35f23fad8a3de8dad683e9758d744142cc15 [file] [log] [blame]
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shell
import "os/exec"
var (
// LocalTarget is an implementation of Target that runs the command on the local machine using the exec package.
LocalTarget Target = localTarget{}
)
type localTarget struct{}
type localProcess struct {
exec *exec.Cmd
}
func (localTarget) Start(cmd Cmd) (Process, error) {
p := &localProcess{
exec: exec.Command(cmd.Name, cmd.Args...),
}
p.exec.Dir = cmd.Dir
p.exec.Stdout = cmd.Stdout
p.exec.Stderr = cmd.Stderr
p.exec.Stdin = cmd.Stdin
p.exec.Env = cmd.Environment
return p, p.exec.Start()
}
func (p *localProcess) Wait() error {
return p.exec.Wait()
}
func (p *localProcess) Kill() error {
return p.exec.Process.Kill()
}