JeffLIrion / adb_shell

A Python implementation of ADB with shell and FileSync functionality.
Apache License 2.0
546 stars 60 forks source link

Not working on windows #88

Closed George-Miao closed 4 years ago

George-Miao commented 4 years ago

Description

Trying to connect to a local simulator (Nox Simulator) on windows, get TypeError while connecting to socket

from adb_shell.adb_device import AdbDeviceTcp
device1 = AdbDeviceTcp('127.0.0.1', 62001)
device1.shell("adb shell input tap 10 10")

Traceback

Traceback (most recent call last):
  File "D:/Work/Projects/PCRHelper/__main__.py", line 3, in <module>
    device1.shell("adb shell input tap 10 10")
  File "D:\Work\env\PCRHelper\lib\site-packages\adb_shell\adb_device.py", line 460, in shell
    return self._service(b'shell', command.encode('utf8'), timeout_s, total_timeout_s, decode)
  File "D:\Work\env\PCRHelper\lib\site-packages\adb_shell\adb_device.py", line 404, in _service
    return b''.join(self._streaming_command(service, command, adb_info)).decode('utf8')
  File "D:\Work\env\PCRHelper\lib\site-packages\adb_shell\adb_device.py", line 1011, in _streaming_command
    self._open(b'%s:%s' % (service, command), adb_info)
  File "D:\Work\env\PCRHelper\lib\site-packages\adb_shell\adb_device.py", line 795, in _open
    self._send(msg, adb_info)
  File "D:\Work\env\PCRHelper\lib\site-packages\adb_shell\adb_device.py", line 980, in _send
    self._handle.bulk_write(msg.pack(), adb_info.timeout_s)
  File "D:\Work\env\PCRHelper\lib\site-packages\adb_shell\handle\tcp_handle.py", line 151, in bulk_write
    _, writeable, _ = select.select([], [self._connection], [], timeout)
TypeError: argument must be an int, or have a fileno() method.

Found a Question on StackOverflow that might be helpful (select doesn't work with non-socket objects on windows)

JeffLIrion commented 4 years ago

You need to call device1.connect() before calling device1.shell. And omit "adb shell" from the command.

JeffLIrion commented 4 years ago

I created a new release that will throw an exception if you try to send an ADB command before connecting to the device.

JeffLIrion commented 4 years ago

I tested this on Windows and it works just fine.