<<< Date Index >>>     <<< Thread Index >>>

Re: piping messages to external scripts



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday, March 19 at 02:22 PM, quoth Culley Harrelson:
> I am ready to tackle this problem but when you pipe a message to a 
> script it looks like a new process is spawned and the new process 
> can't remain in control of the terminal.  Can anyone point me in the 
> right direction to make this happen?

Eh? The new process remains in control of the terminal as long as it 
wants (i.e. it can't give up control at any point). Here's the thing, 
though: when you pipe a message to a script, you're filling the 
standard input with the *message*. If you use typical shell prompting 
mechanisms, they'll all try to pull from standard input, which will 
either be the message or will be *closed* because you already slurped 
it up with something. So, you can't use standard input.

Of course, without stdin, the question becomes: how do you get user 
input? You have to use something more entertaining, like the curses 
library. There's a handy utility that makes this sort of thing easy 
from a shell script (or any other kind of script) called "dialog". You 
can then do things like:

     #!/bin/sh
     tmp=`mktemp -t menubox.XXXX`
     dialog --menu "choose wisely" 0 0 0 \
         1 'pick me' \
         2 'no, really, pick me!' \
         3 'forget those losers' \
         4 'PICK ME!' 2>$tmp
     read choice <$tmp
     echo you picked $choice | less

Read dialog's documentation for all the other neat tricks you can do 
with it---it's surprisingly powerful.

I'm sure there is probably a perl module out there that will do the 
same thing.

~Kyle
- -- 
We will be a better country when each religious group can trust its 
members to obey the dictates of their own religious faith without 
assistance from the legal structure of their country.
                                                       -- Margaret Mead
-----BEGIN PGP SIGNATURE-----
Comment: Thank you for using encryption!

iEYEARECAAYFAkfhjvcACgkQBkIOoMqOI17JhACaA2CcXmEPXQmUYsFMAR+I/o34
YswAoI+HIuWcM/LlZAOvG5J7kGcZyJSv
=b7hp
-----END PGP SIGNATURE-----