[Linux-bruxelles] forcer un exit

Pierre Poissinger pierre.poissinger at gmail.com
Mer 28 Oct 00:04:36 CET 2009


2009/10/26 Ald0 <info at brlspeak.net>

> Hello,
>
> je voudrais pouvoir "forcer" un exit (ou retour au début d'un script) par
> la touche <ENTER>; je m'explique:
>
Tu peux redef INTR via stty - le seul default: ton shell peux continuer a
prendre des INTR dans la figure si tu fais pas gaffe. Tu devrais pouvoir,
via trap, remettre de l'orde.

eg:
8<-------------------------- doHello.sh ------------
#!/bin/sh
# Trap INTR: When it occurs, reset INTR to CTRL-C
trap "stty intr '^C'" 2
# Enter will send INTR
stty intr \13
# Run something
echo "Starting something"
./hello
# I am done
echo "Done"
--------------------------------------------------------->8

Pour la forme, le code C de mon hello 'simulant' un exe genre mplayer....
8<--------------------------hello.c---------------------
#include <stdio.h>
#include <unistd.h>

int main(void) {
  int status=1;
  while(1) {
    printf("%s\n",(status++)%2?"Ping":"Pong");
    sleep(1);
  }
  return 0; /* for grumpy compilers... */
}
-------------------------------------------------------->8

Pas certain que ce soit vraiment solide mais bon, j'étais curieux....

-- 
>>> horsemen = ['war', 'pestilence', 'famine']
>>> horsemen.append('Powerbuilder')
-------------- section suivante --------------
Une pièce jointe HTML a été nettoyée...
URL: </pipermail/linux-bruxelles/attachments/20091028/0a1460c6/attachment-0002.html>


Plus d'informations sur la liste de diffusion Linux-bruxelles