1

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?

Raceimaztion
  • 9,494
  • 4
  • 26
  • 41
  • Why not use os.system()? – Matthew G Jun 03 '13 at 02:13
  • Because then I'd have to figure out how to manage all the appropriate double- and single-quote marks, as well as escaping any embedded quotes. This way, the parameters are already nicely encapsulated. – Raceimaztion Jun 03 '13 at 07:30
  • You could just put them in variables and concatenate them, and use that as the call to os.system(). – Matthew G Jun 06 '13 at 06:16
  • That's not the problem. What if one of the strings I'm using contains double-quotes? I'll have to escape that somehow, probably using two backslashes. I'd rather not have to do that though. This method means that the parameters are passed practically verbatim, with no string parsing between me and it. – Raceimaztion Jun 06 '13 at 21:35

1 Answers1

5

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'])

Dan D.
  • 73,243
  • 15
  • 104
  • 123