impl.go 810 B

1234567891011121314151617181920212223242526272829
  1. package shell
  2. import (
  3. "os"
  4. "os/exec"
  5. )
  6. func (d DeviceShell) RunSync(command string, args ...string) ([]byte, error) {
  7. fc := append([]string{"-s", d.Connection().Device().Serial(), "shell", command}, args...)
  8. return exec.Command(d.Connection().Adb().BinPath(), fc...).CombinedOutput()
  9. }
  10. func (d DeviceShell) StartAsync(command string, args ...string) (*exec.Cmd, error) {
  11. fc := append([]string{"-s", d.connection.Device().Serial(), "shell", command}, args...)
  12. cmd := exec.Command(d.Connection().Adb().BinPath(), fc...)
  13. return cmd, cmd.Start()
  14. }
  15. func (d DeviceShell) StopAsync(cmd *exec.Cmd) error {
  16. if err := cmd.Process.Signal(os.Interrupt); err != nil {
  17. return err
  18. }
  19. if err := cmd.Process.Release(); err == nil || err.Error() == "signal: interrupt" {
  20. return nil
  21. } else {
  22. return err
  23. }
  24. }