如何使用python脚本模拟windows可执行文件的命令?
我在如何使用python脚本模拟windows可执行文件的命令?,python,Python,我在\Users\rjras\Desktop\mqtt\winutils\u 20210211\u 153118处有可执行控件\u client.exe 请在下面找到我用来运行可执行文件的命令: C:\Users\rjras\Desktop\mqtt\winutils_20210211_153118>control_client -mac abcdefgh -user xxx -pass xxx -web_mqtt Control Client for abc company. Versi
\Users\rjras\Desktop\mqtt\winutils\u 20210211\u 153118处有可执行控件\u client.exe
请在下面找到我用来运行可执行文件的命令:
C:\Users\rjras\Desktop\mqtt\winutils_20210211_153118>control_client -mac abcdefgh -user xxx -pass xxx -web_mqtt
Control Client for abc company. Version 1.05.
addr: wss://example.net:443/ws_mqtt
Attempt MQTT connect
Successfully connected via MQTT
subscribe event topic abcdefgh/command/confirm
> position 1 detect on
Sending topic abcdefgh/command/request JSON {"request":"abcdefgh/control/position/1/detect/on","id":0}
> Msg topic: abcdefgh/command/confirm, Payload: {"status":"OK","id":0}
这里有两个命令
control_client-mac abcdefgh-user xxx-pass xxx-web_mqtt
-使用此凭据连接到远程服务器并打开终端。我需要在这里运行第二个命令
位置1检测开启
-检测位置1发生的事件
我在下面编写了一个相当简单的python脚本:
import subprocess
print(subprocess.Popen("control_client -mac abcdefgh -user xxx -pass xxx -web_mqtt",
shell=True, stdout=subprocess.PIPE).stdout.read())
输出:
C:\Users\rjras\PycharmProjects\pythonProject\venv\Scripts\python.exe "C:\Users\rjras\AppData\Local\JetBrains\PyCharm Community Edition 2021.1.1\plugins\python-ce\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 53473 --file C:/Users/rjras/PycharmProjects/pythonProject/main-control_client.py
Connected to pydev debugger (build 211.7142.13)
subscribe event topic abcdefgh/command/confirm
Msg topic: abcdefgh/command/confirm, Payload: {"status":"OK","id":0}
我不知道如何发送脚本中的第二个命令。在关于使用stdin.write()
的快速谷歌中找到了这个命令,也许它会有所帮助?-您可以尝试strout,stderr=p.communicate(“位置1检测打开”)
然后获得结果stdout.read()