Python Forum
execute commands inside a running application
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
execute commands inside a running application
#1
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) ?
Reply
#2
see: https://python-forum.io/thread-35651-pos...#pid150540
Reply
#3
(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.
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python installation/running inside singularity container erdemath 2 1,812 Sep-21-2022, 08:13 AM
Last Post: erdemath
  Python running only in application Mawixy 2 1,142 Apr-19-2022, 11:38 AM
Last Post: Mawixy
  Controlling what get outputted to stdout when running external commands Daring_T 4 2,179 Jan-30-2022, 05:40 PM
Last Post: bowlofred
  How to send data from a python application to an external application aditya_rajiv 1 2,190 Jul-26-2021, 06:00 AM
Last Post: ndc85430
  Possible to execute a python script before log off/shutdown with input commands? Kaltex 1 2,282 May-18-2021, 06:31 AM
Last Post: Skaperen
  Using a .bat file to execute simple anaconda commands in Windows 10 gacg1 0 4,695 Nov-30-2020, 03:24 PM
Last Post: gacg1
  Keep Application running after Python script ends PEGylated_User 0 1,994 Nov-12-2020, 03:27 PM
Last Post: PEGylated_User
  How to assess elapsed time to execute a .exe file or opening a desktop application? Sudershan 2 2,148 Apr-18-2020, 01:40 PM
Last Post: buran
  running multiple commands in a parallel pool Skaperen 6 3,966 Jul-30-2019, 05:49 AM
Last Post: Skaperen
  keep running Console Application MrJoo 3 3,097 Dec-25-2018, 08:59 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020