Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open and close application sequentially in python

I am trying to open and close an application sequentially. But the problem is the application is being opened but to enter to the next line which is the closing line of that application I have to manually close the application.

import os
os.system("scad3 file.txt")
os.system("TASKKILL /PID scad3.exe /T")

scad3 is the application i wish to run,but to enter the next line i.e., taskkilling line, I have to manually close the window please let me know is there any way to solve it??

thank you very much in advance

like image 837
user3582828 Avatar asked Aug 25 '26 06:08

user3582828


1 Answers

I guess os.system is a blocking call. Try using the Popen Objects in python:-

import subprocess
p = subprocess.Popen("notepad.exe")
p.terminate()

Refer :https://docs.python.org/2/library/subprocess.html#popen-objects

like image 138
Anjali Avatar answered Aug 26 '26 20:08

Anjali