E_J
E_J

Reputation: 219

subprocess permission denied

I was looking into how python can start other programs on windows 10, I was on stack overflow and someone said that:

import subprocess
subprocess.call(['C:\\Users\Edvin\Desktop', 'C:\\Example.txt'])

should do it, so I changed the locations so it is specific to me and there was an error which was PermissionError: [WinError 5] Access is denied.

Does anyone know how to grant permission for python to open the file?

I've tried:

import subprocess
subprocess.call(['C:\\Users\\Edvin\\AppData\\Roaming\\Microsoft\\Windows'
                 '\\Start Menu\\Programs\\Accessories\\Notepad.exe'],
                 'C:\\Users\\Edvin\\Desktop\\Example.txt')

but this comes up with TypeError: bufsize must be an integer error.

Upvotes: 3

Views: 11470

Answers (1)

user1361491
user1361491

Reputation:

The thing is that you're trying to launch your desktop as a program. With a text file as an argument.

This is not allowed because you're not allowed to execute the desktop (because it can't be executed).

subprocess.call(["command here", "arguments here"])

if it's an exe use

subprocess.call(['C:\\...\\program.exe', 'argument'])

if it's a python script use

execfile('file.py')

Upvotes: 5

Related Questions