Python: How to Open and Close Programs

preview_player
Показать описание
This video shows you how to open and close programs .exe within python.

Рекомендации по теме
Комментарии
Автор

Wow! After 9 years it still works! Thanks a lot mam!

code-heads
Автор

Still works.
Im shocked.
Thanks so much

BetaTester
Автор

Now that's what I was looking for !!!
wait ...hold on
1 year ago someone else also did???

I'm always late :(

datastock
Автор

def openFile(file):
try:
os.startfile(file)
except Exception as e:
print(str(e))

def closeFile(file):
try:
os.system("TASKKILL /F /IM"+file)
except Exception as e:
print(str(e)) #this is working

lassmicharztichbindurch
Автор

I made text files that list terms for different school subjects. Do you have a video for a python program that you can put in a word as input, and automatically opens a corresponding text-file that has that word in it when you run the program?

suhaasnarayan
Автор

WOW! I am so happy that it worked

YOU JUST GOT A NEW SUBSCRIBER :)

shreyadineshpandey
Автор

How do you close a specific file, rather than all files of that type? In my program, I opened a few specific web pages and only want to close the same webpages that I had opened in my program.

jenmanzella
Автор

Hi Sentdex
Is it possible to open a file without giving the actual file name? Is there any command or keyword wherein the python code must open the existing text file in the given directory without giving the filename.

vpat_patv
Автор

Great tutorial! Thanks! Can you create an automation of actions inside the opened
program? Meaning could you write a code that not only opens the notepad
file but also controls the tab options such as creating a new file maybe writing
some letters, changing the font then writing some more then saves then prints
and only then closes?
Can it be done using code only? I would be glad for resources about this.
At least to know how to call this professionally.

idobooks
Автор

For Python 3 Users:

import os

def openFile() -> object:
try:


except Exception as e:
print (str(e))

openFile()

AzwadAbid
Автор

im on python 3.6.4 and I have fixed (str(e)) I have also switched as before e: but I am still getting an indentation error, any ideas?

BaseballNerd
Автор

Thank you! I'm currently printing statements to a file while I test things, and it was getting _really annoying_ to constantly open and close the text file every time I changed something.

(I suppose I _could_ just figure out how to do breakpoints, but I don't feel like it.)

KoyasuNoBara
Автор

This works on the version of python 3.9.2:

import os

def closeFile():
try:
os.system('TASKKILL /F /IM notepad.exe')
except Exception as e: print(e)

streaky
Автор

How do you open a program and specify screen coordinates where you want it to open at? How do you open a program with a specified dimension(big window, small window)? I am using subprocess to open a video game but im open to suggestions.

ethanlee
Автор

Cool... been looking for that everywhere

erwan
Автор

Hi Sentdex, great how simple and effective you explained it. I'd like to take it one step further, I'm sure you will help me. I need to open an executable, let it run and close the program after it finishes. I managed to do that using pywinauto and setting a timer. So, after X seconds, the program executed would close. However, it is far from efficient because some times it would take 20 seconds, some times it would take 200. I would like to remove that dead time. So, how can I make python know when the executable is finished so that it can kill the application? Thanks in advance (y)

jagfrediani
Автор

AttributeError: module 'os' has no attribute 'startfile'

Zhisaoka
Автор

How do I open actual programs like brackets, or paint, or notepad, or VSCode

WhiteoutMonster
Автор

is it possible to get it to work when you say close notepad it closes the note pad files?

craighetherington
Автор

How do I apply the close program function for a TWB file?

CanDoCookery