Search code examples
pythonpermission-deniedexecv

os.execv PermissionError Errno13 Permission denied


I am trying to run the same program recursively but with a different argument. I am doing it like this:

os.execv(file_dir, ['python'] + [sys.argv[0]] + [str(last_line)])
quit()

This is a snippet of a function that i call from my main function. I tried making sure that that file is executable by doing chmod u+x program.py but that did not work. What can the issue be?


Solution

  • os.execv expects the full path to the executable as the first argument, not a "file directory".

    Try this: os.execv(sys.executable, ['python'] + [sys.argv[0]] + [str(last_line)])

    Example yes implementation by recalling the same executable:

    import sys
    import os
    
    print('y')
    os.execv(sys.executable, ['python'] + [sys.argv[0]])