PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Can't stop script with ctrl-c
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Can't stop script with ctrl-c

Réponse
 
LinkBack Outils de la discussion
Vieux 19/08/2006, 19h16   #1
Dave Farrance
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Can't stop script with ctrl-c

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

--
Dave Farrance
  Réponse avec citation
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
Vieux 19/08/2006, 20h30   #3
Dave Farrance
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can't stop script with ctrl-c

Stephane CHAZELAS <this.address@is.invalid> wrote:

>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.


Festival doesn't seem to ignore the ctrl-c - it will cancel the word
that it's saying and the script goes on to start the next one.

>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).


Thanks. That works.
>
>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.


That works too.

--
Dave Farrance
  Réponse avec citation
Vieux 19/08/2006, 20h53   #4
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can't stop script with ctrl-c

2006-08-19, 19:30(+00), Dave Farrance:
> Stephane CHAZELAS <this.address@is.invalid> wrote:
>
>>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.

>
> Festival doesn't seem to ignore the ctrl-c - it will cancel the word
> that it's saying and the script goes on to start the next one.


Then it probably intercepts the SIGINT, and the handler does a
simple exit.

The net result is that the exit status of festival will not show
that it was terminated by a signal, so bash will not exit.

I don't know why bash is behaving like that. It seems to be the
only shell that does.

--
Stéphane
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h56.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10808 seconds with 12 queries