1

Following the advice of Ignacio ( Python remove spaces and append ) I am trying to convert the below command to use subprocess rather than os.system.

The script: os.system("/usr/local/bin/growlnotify -n emesene -a emesene -t """+title+""" -m """+text+"""""")

I would of thought: subprocess.call(['/usr/local/bin/growlnotify', '-n emesene', '-a emesene', '-t ""+title+"""', '-m """+text+"""""'], shell=True)

But it doesnt work. Any ideas how to get this working? I've looked at the Python docs and looked here, but i cannot figure it out!

BTW the title and text are variables from emesene messengers notification system

1
  • consider to accept Ignacio's answer in the linked question. Commented Jun 10, 2011 at 17:55

2 Answers 2

5

Instead of

subprocess.call(['/usr/local/bin/growlnotify', '-n emesene', '-a emesene', '-t ""+title+"""', '-m """+text+"""""'], shell=True)

use

subprocess.call(['/usr/local/bin/growlnotify', '-n',  'emesene', '-a', 'emesene', '-t', title, '-m', text], shell=True)

Everywhere you have an unquoted space in the shell command, split another list item.

The shlex.split function can be used to convert from a shell-style command to a list of the sort Subproces expects.

Sign up to request clarification or add additional context in comments.

1 Comment

Doesn't work. Gives a blank notification, so i guess its not taking the variables.
4

You don't want "shell=True" when you use a list to pass the command. I would have merely commented as such on Jeremy Banks's post (since his statement on shlex.split is most notable), but I don't currently have the rep to do so :/

subprocess.call(['/usr/local/bin/growlnotify', '-n',  'emesene', '-a', 'emesene', '-t', title, '-m', text])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.