Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended way to run another program from within a Python script [duplicate]

Tags:

python

windows

Possible Duplicate:
How to call external command in Python

I'm writing a Python script on a windows machine. I need to launch another application "OtherApp.exe". What is the most suitable way to do so?

Till now I've been looking at os.system() or os.execl() and they don't quite look appropriate (I don't even know if the latter will work in windows at all).

like image 422
Frederick The Fool Avatar asked May 26 '09 13:05

Frederick The Fool


People also ask

Can you run the same Python file twice?

You can run multiple instances of a python script from a shell however from within a python program without the use of multithreading/multiprocessing the GIL limitation will impact what you are trying to do.

Can one Python script call another?

The first line of 'import python_2' in the python_1 script, would call the second python_2 script. Whenever you want to run one Python script from another, you'll need to import the exact name of the Python script that you'd like to call.


1 Answers

The recommended way is to use the subprocess module. All other ways (like os.system() or exec) are brittle, unsecure and have subtle side effects that you should not need to care about. subprocess replaces all of them.

like image 88
Aaron Digulla Avatar answered Sep 18 '22 15:09

Aaron Digulla