Python Forum

Full Version: execute commands inside a running application
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have an application that execute AT commands on certain device via USB.

First I have to open Terminal, run the application via command line then start to execute AT commands.

Output:
> connectDev (then I press enter) Type in your commands: at+XYZ=? (I start to execute my AT commands)
I tried to write some script with python using subporcess module but it didn't work

my first trial
import subprocess
p1 = subprocess.run(['connectDev'], 
	capture_output=True, 
	text=True)
#print(p1.stdout)
p2 = subprocess.run(['AT+XYZ'],
	capture_output=True, 
	text=True) 
print(p2.stdout)
the script was waiting for the application to finish but it keep waiting.

I also tried :
import subprocess
results = subprocess.Popen(['connectDev'], 
	stdout=subprocess.PIPE,
	stderr=subprocess.PIPE, 
	text=True)
results.poll()
stdout,stderr = results.communicate()
print(stdout)
is there anyway that I can run the AT commands using Python after I exeucte the application(connectDev) ?
(Apr-11-2022, 08:39 PM)Larz60+ Wrote: [ -> ]see: https://python-forum.io/thread-35651-pos...#pid150540
Thx anyway.
I already saw it before I wrote the thread.
the post you send, connects the device via ttyUSB but mine requires an application to connect.
the application is doing a lot of things rather than connecting to USB since there there some protection added to connect to this device.
my_byte31 Wrote:the post you send, connects the device via ttyUSB but mine requires an application to connect.
the application is doing a lot of things rather than connecting to USB since there there some protection added to connect to this device.

The thread shown shows an application that connects, reads and writes AT commands.
You can add whatever you wish in addition to that.
I guess I don't understand exactly what you are looking for.
Using a subprocess executes the commands outside of the application.