簡體   English   中英

WindowsError [錯誤5]訪問被拒絕

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM