Running a external program using Python


April 2019


28 time


I want to launch a external program like notepad.exe using python. I want to have a script that just runs Notepad.exe.

3 answers


Would recommend the subprocess module. Just build up a list of arguments like you would run in the terminal or command line if you are on windows then run it.

import subprocess

args = ['path\to\program\here\program.exe']

Check out the docs here for all of the other process management functionality.


It's really simple with Python's builtin os module.
This will start Microsoft Notepad:

import os

# can be called without the filepath, because notepad is added to your PATH

Or if you want to launch any other program just use:

import os

# r for raw-string, so don't have to escape backslashes

this can be done using Python OS. Please see the code below for an example.

import os

Startfile will execute the program associated with the file extension.