简体   繁体   English

WindowsError [错误5]访问被拒绝

[英]WindowsError [error 5] Access is denied

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: 我正在使用killableprocess包(构建在子进程之上)来运行进程每当我在脚本中运行“killableprocess.Popen(command)”代码时,我都会收到以下错误:

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. 但是当我从python交互式控制台(python 2.6)运行它时它工作正常。 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. 我尝试从我以管理员身份运行的cmd运行脚本,但它没有帮助。 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. 希望在这里找到一些帮助我在Windows上运行,特别是Windows 7 Ultimate x64,如果有任何帮助的话。

thanks 谢谢

I solved a similar problem I had by switching to the process directory (I was trying to use inkscape) and it solved my problem 我通过切换到进程目录(我试图使用inkscape)解决了类似的问题,它解决了我的问题

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. 也许切换到进程目录也适合你。

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. 在使用子进程模块运行时我发现的是'args'中的第一个条目( subprocess.Popen()的第一个参数)需要只是没有路径的可执行文件名,我需要在参数中设置executable列出我的可执行文件的完整路径。

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

commandLine = [app, 'arg1', 'arg2']
process = subprocess.Popen(commandLine, executable=appPath)

确保您的路径包含可执行文件的名称(inkscape.exe)

Alternatively, if your module doesn't work, you can use the «subprocess» module: 或者,如果您的模块不起作用,您可以使用«subprocess»模块:

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) 

您是否指定了传递给Popen可执行文件的完整路径argv的第一项)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM