How to simulate the commands of windows executable using python script?

Viewed 71

I have executable control_client.exe at \Users\rjras\Desktop\mqtt\winutils_20210211_153118

Please find below the commands that I use to run the executable:

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}

There are two commands here.

  1. control_client -mac abcdefgh -user xxx -pass xxx -web_mqtt - Connects to remote server using this credentials and opens a terminal. I need to run the second command here.
  2. position 1 detect on - It detects that the event at position 1 occurred.

I have written an equivent simple python script below:

import subprocess

print(subprocess.Popen("control_client -mac abcdefgh -user xxx -pass xxx -web_mqtt",
                       shell=True, stdout=subprocess.PIPE).stdout.read())

Output:

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}

I am not sure how do I send the second command in the script.

0 Answers
Related