View previous topic :: View next topic |
Author |
Message |
croquignol Tux's lil' helper
Joined: 16 Sep 2005 Posts: 125
|
Posted: Wed Oct 26, 2005 4:14 pm Post subject: [BASH] redirection avec affichage (resolu) |
|
|
Lorsque j'execute une commande, je souhaite recuperer l'affichage a l'ecran dans un fichier texte afin de le consulter plus tard. Aussi je redirige la sortie standard (1) dans un fichier ecran.txt et la sortie standard d'erreur (2) vers le fichier erreur.txt. La syntaxe utilisee est la suivante :
Code: | commande 1>ecran.txt 2>erreur.txt |
Le probleme est que l'affichage a l'ecran que l'on aurait obtenu avec la commande seule ne se fait plus.
1) Comment modifier cette syntaxe afin de rediriger 1 et 2 vers les fichiers respectifs tout en conservant l'affichage a l'ecran ?
Last edited by croquignol on Thu Oct 27, 2005 11:03 am; edited 1 time in total |
|
Back to top |
|
|
Starch Guru
Joined: 26 Feb 2003 Posts: 539 Location: Rennes, France
|
Posted: Wed Oct 26, 2005 4:28 pm Post subject: |
|
|
de tête je crois que ce n'est pas possible ou très fin. _________________ - Vous aurez beau dire... Y'a pas qu'd'la pomme... Y'aurait pas aussi d'la betterave ?
- Si, y'en a aussi |
|
Back to top |
|
|
naerex Guru
Joined: 02 Apr 2005 Posts: 316 Location: Paris, France
|
Posted: Wed Oct 26, 2005 4:29 pm Post subject: |
|
|
il y a bien la commande tee
Code: | command | tee fichier.txt |
Mais ça ne redirigera que stdout |
|
Back to top |
|
|
xaviermiller Bodhisattva
Joined: 23 Jul 2004 Posts: 8710 Location: ~Brussels - Belgique
|
Posted: Wed Oct 26, 2005 4:32 pm Post subject: |
|
|
et
Code: | command | tee fichier.txt 2| tee erreurs.txt |
_________________ Kind regards,
Xavier Miller |
|
Back to top |
|
|
netfab Veteran
Joined: 03 Mar 2005 Posts: 1906 Location: 127.0.0.1
|
Posted: Wed Oct 26, 2005 4:37 pm Post subject: |
|
|
Au cas où, si tu ne trouves pas de meilleure solution :
Code: |
commande 1>ecran.txt 2> erreur.txt | cat ecran.txt
|
Mais, attendons les pros du bash |
|
Back to top |
|
|
bdz Apprentice
Joined: 15 Jul 2005 Posts: 237 Location: Montpellier (France)
|
Posted: Wed Oct 26, 2005 4:41 pm Post subject: |
|
|
Et ca?
Code: | commande 2>&1 | tee fichier.txt
|
Ca redirige la sortie d'erreur vers la sortie standard et tee envoi tout ca dans un fichier et a l'écran.
Inconvenient: erreur et standard sont dans le même fichier (mais ca peut être un avantage en fonction de ce qu'on veut faire) |
|
Back to top |
|
|
naerex Guru
Joined: 02 Apr 2005 Posts: 316 Location: Paris, France
|
Posted: Wed Oct 26, 2005 4:44 pm Post subject: |
|
|
Je crois que c'est ça, mais je n'ai pas de prog pour le tester, mon fichier erreur reste vide.
Code: | cmd | tee ecran.txt 2> erreur.txt |
|
|
Back to top |
|
|
bdz Apprentice
Joined: 15 Jul 2005 Posts: 237 Location: Montpellier (France)
|
Posted: Wed Oct 26, 2005 4:46 pm Post subject: |
|
|
naerex wrote: | Je crois que c'est ça, mais je n'ai pas de prog pour le tester, mon fichier erreur reste vide.
Code: | cmd | tee ecran.txt 2> erreur.txt |
| Là c'est la sortie d'erreur de tee que tu redirige vers un fichier.
Tu peux tester avec cette commande:
Code: | ls Fichier.Qui.N.Existe.Pas |
qui provoque une erreur |
|
Back to top |
|
|
naerex Guru
Joined: 02 Apr 2005 Posts: 316 Location: Paris, France
|
Posted: Wed Oct 26, 2005 4:49 pm Post subject: |
|
|
exact bdz je redirige stderr de tee, il nous a posé une sacré colle là le croquignol |
|
Back to top |
|
|
bdz Apprentice
Joined: 15 Jul 2005 Posts: 237 Location: Montpellier (France)
|
Posted: Wed Oct 26, 2005 4:54 pm Post subject: |
|
|
Si ca ne le dérange pas d'avoir tout dans un seul fichier la commande de mon post un peu plus haut fonctionne, je l'utilise régulièrement.
Après pour avoir sortie standard et sortie d'erreur dans deux fichiers mais les deux a l'écran comme avec la commande normale ca doit être plus subtil. |
|
Back to top |
|
|
boozo Advocate
Joined: 01 Jul 2004 Posts: 3193
|
|
Back to top |
|
|
Starch Guru
Joined: 26 Feb 2003 Posts: 539 Location: Rennes, France
|
Posted: Wed Oct 26, 2005 8:00 pm Post subject: |
|
|
Je persiste à penser que ce n'est pas possible en bash.
Par contre en perl...
_________________ - Vous aurez beau dire... Y'a pas qu'd'la pomme... Y'aurait pas aussi d'la betterave ?
- Si, y'en a aussi |
|
Back to top |
|
|
boozo Advocate
Joined: 01 Jul 2004 Posts: 3193
|
|
Back to top |
|
|
bdz Apprentice
Joined: 15 Jul 2005 Posts: 237 Location: Montpellier (France)
|
Posted: Wed Oct 26, 2005 8:29 pm Post subject: |
|
|
Starch wrote: | Je persiste à penser que ce n'est pas possible en bash.] |
Rien n'est impossible:
Code: | b12@quasar ~ $ (ls /home ca.existe.pas | tee std.txt) 3>&1 1>&2 2>&3 3>&- | tee err.txt
ls: ca.existe.pas: No such file or directory
/home:
b12
b12@quasar ~ $ cat std.txt
/home:
b12
b12@quasar ~ $ cat err.txt
ls: ca.existe.pas: No such file or directory |
|
|
Back to top |
|
|
boozo Advocate
Joined: 01 Jul 2004 Posts: 3193
|
|
Back to top |
|
|
Starch Guru
Joined: 26 Feb 2003 Posts: 539 Location: Rennes, France
|
Posted: Wed Oct 26, 2005 8:37 pm Post subject: |
|
|
au temps pour moi alors _________________ - Vous aurez beau dire... Y'a pas qu'd'la pomme... Y'aurait pas aussi d'la betterave ?
- Si, y'en a aussi |
|
Back to top |
|
|
nemo13 Veteran
Joined: 08 Oct 2004 Posts: 1016 Location: France/Istres
|
Posted: Wed Oct 26, 2005 8:39 pm Post subject: |
|
|
Bonsoir,
en tant que Jeune dans le métier, j'utilise un truc tout simple avec Xterm
[CTRL]+ (bouton gauche de la souris ) et je "clique" sur Log to File
ce qui me donne dans ~ un fichier xterm.date.heure qu'il me reste à éplucher.
voili-voila |
|
Back to top |
|
|
boozo Advocate
Joined: 01 Jul 2004 Posts: 3193
|
|
Back to top |
|
|
bdz Apprentice
Joined: 15 Jul 2005 Posts: 237 Location: Montpellier (France)
|
Posted: Wed Oct 26, 2005 8:51 pm Post subject: |
|
|
boozo wrote: | mais 5 process et 3 descripteurs |
On doit pouvoir faire encore pire |
|
Back to top |
|
|
croquignol Tux's lil' helper
Joined: 16 Sep 2005 Posts: 125
|
Posted: Thu Oct 27, 2005 11:02 am Post subject: |
|
|
Merci pour toutes ces reponses. La reponse de bdz est celle que je cherchais. En surfant, j'ai trouve le site http://www.cpqlinux.com/redirect.html qui donne un exemple. |
|
Back to top |
|
|
|