Search code examples
pythonexeclibnotify

Python os.exec(): Termination on running 'notify-send'


I'm writing a small Python script under Linux that pops up a number of libnotify pop-ups, currently by using the following syntax:

import os
os.execv('/usr/bin/notify-send', ['App Title', 'Message'])

Unfortunately, and for some strange reason, it kills the interpreter right out to the command-prompt.
It doesn't do this with any other command the script executes, just notify-send.

There's no error given, no known exception thrown, no indication of anything wrong, it just dies out to the command prompt.

Does anyone have suggestions or alternatives that equally easy to do?


Solution

  • You should use subprocess.call which starts the program named by its arguments in a new process and waits for the child process to exit rather than os.execv which replaces what is running in the current process with the program specified by its arguments.

    The usage is subprocess.call(['/usr/bin/notify-send', 'App Title', 'Message'])