Alessandro Gaballo
Alessandro Gaballo

Reputation: 770

Open Windows Camera from Python application

I need to open the Windows 10 camera app and possibly close it after a few seconds so that my camera will work the proper way. I've read in realted questions that I'm supposed to use os.subprocess.run() but I'm not sure what should go in there. I've seen posts about opening the Camera from the command line by doing start microsoft.windows.camera in the command line but it's not working. Any idea?

Upvotes: 1

Views: 6128

Answers (2)

user12367172
user12367172

Reputation: 31

To open camera:

import subprocess,os
subprocess.run('start microsoft.windows.camera:', shell=True)

To close camera:

subprocess.run('Taskkill /IM WindowsCamera.exe /F', shell=True)

If it says it doesn't recognise- WindowsCamera.exe Type Tasklist into your computers command prompt and look for what your camera is called before .exe then adapt the above code to your camera name.

code all together, to check if works:

import subprocess,time,os
subprocess.run('start microsoft.windows.camera:', shell=True)
time.sleep(10)
subprocess.run('Taskkill /IM WindowsCamera.exe /F', shell=True)

Upvotes: 3

Sav
Sav

Reputation: 656

So, with comments

import subprocess

subprocess.run('start microsoft.windows.camera:', shell=True)

#camera = subprocess.Popen('start microsoft.windows.camera:', shell=True)
#camera.terminate()  # don't work, access denied :(

works, but I can't close camera from script

Upvotes: 1

Related Questions