escaping parentheses in alertcmd

21 views
Skip to first unread message

Mel

unread,
Apr 1, 2012, 11:43:45 PM4/1/12
to Event and Task Manager
At least on Linux, if there are parentheses in the text of
the alert message passed to the "alertcmd", it fails when it
is passed to the shell with 'sh: Syntax error: "(" unexpected'.

In function onAlert in file etmWX.py I worked around this with,
cmd = cmd.replace("(", "\(")
cmd = cmd.replace(")", "\)")
before the call to os.system(cmd).
Not sure this is the right fix and I guess there are other
characters to escape also?

Mel

unread,
Apr 6, 2012, 10:53:00 AM4/6/12
to Event and Task Manager
I also needed:

cmd = cmd.replace("'", "\\'")

And I think another one that may be wanted is?

cmd = cmd.replace("`", "\\`")

Dan

unread,
Apr 6, 2012, 4:42:34 PM4/6/12
to eventandt...@googlegroups.com
Mel,

Could you give an example of an alert message and an alertcmd that causes the problem?

Thanks,
Dan

Mel

unread,
Apr 7, 2012, 4:10:29 PM4/7/12
to Event and Task Manager
Alert message (line in etmdata .text file):

* Feed Jack's dog (silly) @d Apr 7 2012 @a5 @s 4:05pm @e+0

Alert command:
alertcmd = '''msgat -c yellow/reverse now %(m)s [etm %(T)s]'''

My shell script "msgat" writes it's arguments to a file,
but the actual command doesn't matter since the call to
os.system() gets a shell error from the arguments before
it can execute anything.

sh: Syntax error: Unterminated quoted string

In the above case it fails on the single quote in "jack's"
but if that is removed it would then fail on the parenthesis
in "(silly)".

Dan

unread,
Apr 8, 2012, 11:54:27 AM4/8/12
to eventandt...@googlegroups.com
Mel,

I can't duplicate this either under unbuntu or os x lion.  Would you try modifying your alertcmd as follows?

 alertcmd = '''msgat -c yellow/reverse now "%(m)s" [etm "%(T)s"] '''

-Dan

Mel

unread,
Apr 8, 2012, 9:05:23 PM4/8/12
to Event and Task Manager
Dan,
Yes using double quotes to escape the text passed to the shell
fixes it (and is a better way to do it). Thanks, don't know
why I didn't think to do that. BTW, I'm using ubuntu also,
so not sure why you couldn't duplicate it.

Dan

unread,
Apr 9, 2012, 1:42:59 PM4/9/12
to eventandt...@googlegroups.com
Mel,

I first tried to duplicate the problem using your alert message but not your alert command.  When I couldn't, I compared your alertcmd to mine and noticed the missing quotes.  Sorry for misleading you.

-Dan
Reply all
Reply to author
Forward
0 new messages