Windows错误 [错误 5] 拒绝访问
我正在使用一个叫做killableprocess的包(这个包是基于subprocess构建的)来运行进程。每当我在脚本中运行“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)中运行时,一切都正常。这可能意味着在脚本中运行时有权限问题,但我不知道该怎么解决。我尝试从一个以管理员身份运行的命令提示符中运行这个脚本,但没有帮助。我也试着找类似的帖子,但没有找到好的解决方案。希望在这里能找到一些帮助。我是在Windows上运行,具体是Windows 7 Ultimate x64,如果这有帮助的话。
谢谢
5 个回答
4
确保你的路径中包含可执行文件的名字(inkscape.exe)
10
我在使用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)
19
我遇到过类似的问题,后来我试着切换到进程目录(我当时在用 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])
也许切换到进程目录对你也有帮助。