Search code examples
rubycygwingrowl

calling growlnotify from inside cygwin from inside ruby


I'm having some trouble with calling growlnotify from within a ruby script running on cygwin on a Windows 7 machine. I suspect this is doable but there are a few too many layers of interpretation happening and I can't figure out what the right escape sequence needs to be.

The following code (with no custom icon specified) is working fine:

#!/usr/bin/ruby

l = "Hello World"

system("/cygdrive/c/Program\\ Files\\ \\(x86\\)/Growl\\ for\\ Windows/growlnotify /t:testedfa  \'#{l}\'")

However, when I try to specify an icon things start to fail. Depending on how many layers of escape characters I try, the command will either do nothing at all or growlnotify will crash. Specifically with the code shown below, I get no response from Growl at all.

#!/usr/bin/ruby

l = "Hello World"

system("/cygdrive/c/Program\\ Files\\ \\(x86\\)/Growl\\ for\\ Windows/growlnotify /t:testedfa /i:C:\\\workspace\\\tryCPUnit\\\amp\\\testedfa\\\pass.png \\\'#{l}\\

Any ideas?


Solution

  • Try the multi-argument form of system, that will remove one layer of escaping by bypassing the shell. Something like this:

    system(
        '/cygdrive/c/Program Files (x86)/Growl for Windows/growlnotify',
        '/t:testedfa',
        '/i:C:/workspace/tryCPUnit/amp/testedfa/pass.png',
        l
    )
    

    Windows generally accepts forward or backward slashes so I cleaned up your /i switch a bit, go back to \\ if it doesn't like that path.

    Using the single argument system is almost always just a bug waiting to happen, I wouldn't use it unless there was no other way (and I can't think of when there wouldn't be a better way ATM).