Afficher un message
Vieux 19/08/2006, 19h49   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can't stop script with ctrl-c

2006-08-19, 18:16(+00), Dave Farrance:
> This script uses the "festival" speech synthesis app to keep saying the
> word hello. Why can't I stop it with ctrl-c? Is there a workaround?
>
> #!/bin/bash
> while true; do
> echo "hello" | festival --tts
> done


Yes, bash has a funny way of handling sigint. bash will only
exit upon receiving a SIGINT if the current command was killed
by that sigint as well (apparently).

So, if "festival" ignores the sigints, it will not exit.

You can try:


#! /bin/bash -
while :; do
echo "hello" | festival --tts &
wait
done

Then, the CTRL-C will interrup the "wait" instead of festival
(which will continue running).

Or:

#! /bin/bash -
trap 'exit 1' INT
while :; do
echo "hello" | festival --tts
done

This way, bash will still block the SIGINT but will execute its
handler (exit 1) when festival finishes.

--
Stéphane
  Réponse avec citation
 
Page generated in 0,05381 seconds with 9 queries