Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Open Multiple applications using Python

I want to start multiple applications using python script, basically there will be one text file which contains the paths of executable files and I want to open all of those applications one by one.
I tried it by using subprocess.Popen but it opens only first application from text file and even it executes only when text file has path of only one application, if I try to save multiple paths in text file then python script shows an error: [WinError 2] The system cannot find the file specified
I tried with readlines method too, but it didn’t worked

Below is the code I’m trying to execute

with open(path) as file:
   for x in file:
      subprocess.Popen(x)


Paths.txt file: 
C:\Windows\notepad.exe 
C:\Program Files\Sublime Text\sublime_text.exe

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The following works for me.

import subprocess
import time

with open('path.txt') as file:
   for x in file:
      subprocess.Popen(x.strip())

time.sleep(10)

# Content of path.txt:
#
# C:\Windows\notepad.exe 
# C:\Program Files (x86)\Notepad++\notepad++.exe
# C:\Program Files (x86)\Simple Sudoku\simplesudoku.exe
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading