WindowsError [error 5] Access is denied
Asked Answered
D

5

32

I'm using the killableprocess package (built on top of subprocess) for running processes Whenever I run the "killableprocess.Popen(command)" piece of code in my script I get the following error:

File "killableprocess.py", line 157, in _execute_child
  winprocess.AssignProcessToJobObject(self._job, hp)
File "winprocess.py", line 37, in ErrCheckBool
  raise WinError()
WindowsError [error 5] Access is denied
Exception TypeError: "'NoneType' object is not callable" in <bound method AutoHANDLE.__del__ of <AutoHANDLE object at 0x025D42B0>> ignored

But when I run it from the python interactive console (python 2.6) it works fine. That probably means there are permission issues when I run this from the script, but I don't know how to solve them. I tried running the script from a cmd that I ran as administrator, but it didn't help. Tried looking for similar posts but didn't find any good solution. Hope to find some help here I'm running on Windows, specifically Windows 7 Ultimate x64, if it's any help.

thanks

Devland answered 9/6, 2010 at 11:42 Comment(0)
A
19

I solved a similar problem I had by switching to the process directory (I was trying to use inkscape) and it solved my problem

import subprocess
inkscape_dir=r"C:\Program Files (x86)\Inkscape"
assert os.path.isdir(inkscape_dir)
os.chdir(inkscape_dir)
subprocess.Popen(['inkscape.exe',"-f",fname,"-e",fname_png])

Maybe switching to the process directory will work for you too.

Argyres answered 20/8, 2011 at 9:6 Comment(0)
I
10

What I found when running into this with the subprocess module is that the first entry in 'args' (the first parameter to subprocess.Popen()) needed to be just the executable name with no path and I needed to set executable in the argument list to the full path of my executable.

app = 'app.exe'
appPath = os.path.join(BIN_DIR, app)

commandLine = [app, 'arg1', 'arg2']
process = subprocess.Popen(commandLine, executable=appPath)
Irenairene answered 12/12, 2012 at 2:36 Comment(2)
Pay attention to the current working directory too; other answers suggest needing to os.chdir(other_dir) before starting the process and that may be true depending on the implementation of the process itself. However you can also just use the cwd=other_dir argument to Popen to set the cwd without needing to change it for the script itself.Irenairene
executable=... didn't work for me at all, but os.chdir() did. cwd= works as well and it seems for me to be a nicest answer.Gennygeno
D
4

Make sure that your paths include the name of the executable file (inkscape.exe)

Desecrate answered 27/6, 2013 at 2:3 Comment(1)
very hard to catch this one!Nympholepsy
F
2

Alternatively, if your module doesn't work, you can use the «subprocess» module:

import subprocess, os, time

process = subprocess.Popen("somecommand", shell=True)
n = 0
while True:
    if not process.poll():
        print('The command is running...')
        if n >= 10:
            pid = process.pid
            os.kill(pid, 9) # 9 = SIGKILL
    else:
        print('The command is not running..')
    n += 1
    time.sleep(1) 
Filberte answered 6/1, 2011 at 16:11 Comment(1)
Take out the parentheses on process.pid() ("TypeError: 'int' object is not callable")Acinaciform
D
0

Do you specify full path to executable you are passing to Popen (the first item in argv)?

Diphyllous answered 16/1, 2011 at 15:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.