WindowsError [错误 5] 访问被拒绝

发布于 2024-09-04 17:36:38 字数 704 浏览 3 评论 0原文

我正在使用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

但是当我从 python 交互式控制台 (python 2.6) 运行它时,它工作正常。 这可能意味着当我从脚本运行它时存在权限问题,但我不知道如何解决它们。我尝试从以管理员身份运行的cmd运行脚本,但没有帮助。 尝试寻找类似的帖子但没有找到任何好的解决方案。希望在这里能找到一些帮助 我正在 Windows 上运行,特别是 Windows 7 Ultimate x64,如果有帮助的话。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

穿越时光隧道 2024-09-11 17:36:38

我通过切换到进程目录解决了类似的问题(我试图使用 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])

也许切换到进程目录也适合你。

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.

春风十里 2024-09-11 17:36:38

我在使用 subprocess 模块遇到此问题时发现,“args”中的第一个条目(subprocess.Popen() 的第一个参数)只需是没有路径的可执行文件名称,我需要将参数列表中的executable设置为我的可执行文件的完整路径。

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

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

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)
空气里的味道 2024-09-11 17:36:38

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

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

半衬遮猫 2024-09-11 17:36:38

或者,如果您的模块不起作用,您可以使用“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) 

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) 
皇甫轩 2024-09-11 17:36:38

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文