cancel stdout of a process that started using os.execvp()

Viewed 27

I'm trying to start a process with os.execvp but I want to cancel its stdout.

I have tried to change sys.stdout to os.devnull but it didn't work.

sys.stdout = open(os.devnull, 'w')
os.execvp(proc_path, proc_args)

I also tried to use os.dup2 to change the file description and it didn't work as well.

STDOUT = 1

fdout = os.open(os.devnull, os.O_WRONLY)
os.dup2(fdout, STDOUT)
os.execvp(proc_path, proc_args)

Do you know any better way to do that?

0 Answers
Related