Using subprocess to Run Any App
00:00
In the previous lesson, you learned how to use subprocess
to run Python. Well, you can run other apps and that’s what you will learn in this lesson.
00:10
Say, I would like to open a text editor. subprocess
has been imported, so instead of Python, let me start something else. So subprocess.run()
as per the documentation, and then I open up a list and well, here’s a question, which text editor do I want to open?
00:31 Now, if you are on Windows, you’ll most likely have Notepad. Now that is not going to work for me because I am on Linux and Linux, at least my distro, does not have Notepad installed.
00:45
So I will need to pick one that’s installed on my machine and one of those will be nano
. So if I now hit Enter, there you go. That is the nano
text editor, and I’m going to close this by pressing Ctrl + x.
01:02
After your first example, what is it that you have learned? Well, firstly, you have learned how to use subprocess
from within Python to launch another Python process that then launched a Python app.
01:15
Secondly, from within Python, you have used subprocess
to launch another app, and the example was a text editor, Notepad on Windows or nano
on my Linux distro.
01:28
You also looked at the CompletedProcess
object. Well, at least we had a very brief look at it. We mentioned it, and in the next lesson, you look at this object in more detail.
Become a Member to join the conversation.