当我在windows 10上从powershell运行python脚本时,该脚本成功运行,但最后它输出了以下内容,尽管我从未键入过类似的命令 es
```
'es' is not recognized as an internal or external command,
显示此错误消息后,我还发现一个由以下名称生成的空文件(没有扩展名):
datetime(2021
该错误是间歇性的,从同一个powershell的同一目录运行同一个python脚本的次数占20%。
我在跑步 `python myfile.py` 这里是代码 `myfile.py` ```
from __future__ import print_function
from dateutil.relativedelta import relativedelta
from device_facade_v2 import DeviceFacade
from google.auth.transport.requests import Request
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from pathlib import Path
from ppadb.client import Client as AdbClient
import colorama
import pprint as pp
import requests
import socket
global device_id
filepath = str(Path(__file__).resolve())
if "/" in filepath:
pathsplit = filepath.split("/")
else:
pathsplit = filepath.split("\\")
root = "/".join(pathsplit[:-1])
adb_host_ip = socket.gethostbyname(socket.gethostname())
def get_adb_devices():
client = AdbClient(host="127.0.0.1", port=5037)
devices = client.devices()
adb_device_list = []
for device in devices:
try:
print()
print("DEVICE:" + device.serial)
prop = device.shell("getprop")
proplines = prop.split("\n")
for propline in proplines:
if "[ro.product.board]" in propline:
# print(propline)
board = (
propline.split(":")[1].replace("[", "").replace("]", "").strip()
)
if "[ro.product.brand]" in propline:
# print(propline)
brand = (
propline.split(":")[1].replace("[", "").replace("]", "").strip()
)
if "[ro.product.model]" in propline:
print(propline)
model = (
propline.split(":")[1].replace("[", "").replace("]", "").strip()
)
try:
socket.inet_aton(device.serial.split(":")[0])
print(device.serial.split(":")[0])
adb_device_list.append(
{
"serial": device.serial,
"ip_address": device.serial.split(":")[0],
"board": board,
"brand": brand,
"model": model,
}
)
continue
except socket.error:
pass
ip_address_blob = device.shell("ip addr")
ip_address_splits = ip_address_blob.split(" ")
ip_address_splits_cleaned = []
for comp in ip_address_splits:
if "192.168." not in comp:
continue
ip_address_splits_cleaned.append(comp)
print(ip_address_splits_cleaned)
for comp in ip_address_splits:
if len(comp) < 11 or len(comp) > 18:
continue
if "192.168." not in comp:
continue
if "192.168.0.255" in comp:
continue
if "192.168.68.255" in comp:
continue
try:
socket.inet_aton(comp)
adb_device_list.append(
{
"serial": device.serial,
"ip_address": comp,
"board": board,
"brand": brand,
"model": model,
}
)
# print(comp.split("/")[0])
except socket.error:
pass
except Exception as e:
pass
return adb_device_list
if __name__ == "__main__":
connected_devices = get_adb_devices()
print("\n\nconnected_devices(raw):")
pp.pprint(connected_devices)
print("\n\nconnected_devices(unsorted):")
for connected_device in connected_devices:
connected_device["port"] = ""
try:
connected_device["port"] = connected_device["serial"].split(":")[1]
except Exception as e:
pass
print(connected_device["serial"], connected_device["model"])
connected_devices = sorted(connected_devices, key=lambda k: k["port"])
print("\n\n {} connected_devices(sorted):".format(len(connected_devices)))
for connected_device in connected_devices:
print(connected_device["serial"], connected_device["model"])
根据请求添加了代码,尽管我认为代码与此无关。它发生在我所有的python文件中,不管该文件中有什么代码。
下面是powershell上输出的屏幕截图:(检查最后一行的错误消息,即显示所有成功输出后)https://snipboard.io/rhnanp.jpg
1条答案
按热度按时间h9vpoimq1#
通过提升的命令提示符运行以下命令似乎解决了这个问题。
有关windows修复的详细信息,请检查此