Module function containing Popen gets permission denied but works outside of module function

Viewed 36

Banging my head on this. There are many posts on popen permission denied errors, but none seem to be helping me. Any tips or pointers in the right direction would be awesome! Thank you all : )

This is on a raspberry pi, python 3.7.3

The following works as expected: sudo python3 test.py The subprocess opens with no problem.

#Filename "test.py"
import subprocess
proc = subprocess.Popen("./my_compiled_c_file")
print(proc.pid)
exit()

If I instead import a modified test.py as a module the following command gets a permission denied error on "./my_compiled_c_file": sudo python3 main_test.py

#Filename "/subfolder/test.py"
import subprocess
def proc_open():
    proc = subprocess.Popen("./my_compiled_c_file")
    return proc.pid
#Filename "main_test.py"
import subfolder.test as TEST

if __name__ = '__main__':
    pid = TEST.proc_open()
    print(pid)
    exit()

I'm certain I'm a dummy, I just dont know how dumb yet...

1 Answers

Pretty dumb, those previous posts should have helped...

proc = subprocess.Popen('sudo /absolute/path/to/file', shell=True)
Related