[英]WindowsError [error 5] Access is denied
我正在使用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,如果有任何帮助的话。
谢谢
我通过切换到进程目录(我试图使用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])
也许切换到进程目录也适合你。
在使用子进程模块运行时我发现的是'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)
或者,如果您的模块不起作用,您可以使用«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.