Une question qu'on m'a pos� sur une autre ml:

> Cela fait un bout de temps que j'essaie de trouver une solution
> pour voir un code d'erreur d'une commande qui est lanc�e en arri�re
> plan ?

hum.

   schaefer@defian:~% echo -e '#! /bin/sh\nexit 42' > /tmp/error_script.sh \\
                      && chmod a+rx /tmp/error_script.sh
   schaefer@defian:~% /tmp/error_script.sh; echo $?
   42

en arri�re-plan:

   schaefer@defian:~% (/tmp/error_script.sh &); echo $?
   0

effectivement, �a marche pas et c'est normal: il faut introduire une
synchronicit� (pardon):

   schaefer@defian:~% help wait
   wait: wait [n]
     Wait for the specified process and report its termination status.  If
     N is not given, all currently active child processes are waited for,
     and the return code is zero.  N may be a process ID or a job
     specification; if a job spec is given, all processes in the job's
     pipeline are waited for.

Donc il faut sp�cifier le processus attendu en param�tre. Cet identifiant
doit �tre stock� dans une variable juste apr�s le lancement de la commande
concern�e en parall�le (ou du moins avant le lancement d'une autre). On le
trouve dans: $!

Je n'ai pas vraiment cherch�, mais � voir ce truc ne marche bien que dans
des scripts, pas interactivement.

Il marche dans ce script:

   schaefer@defian:~% more /tmp/launcher_script.sh 
   #! /bin/sh

   /tmp/error_script.sh &
   THE_PID=$!

   echo PID was $THE_PID
   wait $THE_PID
   echo $?

R�sultat:
   schaefer@defian:~% sh /tmp/launcher_script.sh 
   PID was 1237
   42


--
http://www-internal.alphanet.ch/linux-leman/ avant de poser
une question. Ouais, pour se d�sabonner aussi.

Répondre à