WindowsError [error 5] Access is denied

后端 未结 5 1002
無奈伤痛
無奈伤痛 2020-12-03 04:39

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

相关标签:
5条回答
  • 2020-12-03 05:09

    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)
    
    0 讨论(0)
  • 2020-12-03 05:12

    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.

    0 讨论(0)
  • 2020-12-03 05:30

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

    0 讨论(0)
  • 2020-12-03 05:30

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

    0 讨论(0)
  • 2020-12-03 05:31

    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) 
    
    0 讨论(0)
提交回复
热议问题