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 > Redirect output to x-window in linux?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Redirect output to x-window in linux?

Réponse
 
LinkBack Outils de la discussion
Vieux 24/08/2006, 15h11   #1
Dave Farrance
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Redirect output to x-window in linux?

Is it possible for a bash script to test it it's not running in a
terminal and if that's the case, pop open an x-window of some sort (in
linux) and redirect the output of the remaining commands in that script
to the x-window?

The test is easy enough: [ "$TERM" == "dumb" ]

....but I can't figure out how to redirect the output of the remaining
script commands to an x-window.

--
Dave Farrance
  Réponse avec citation
Vieux 24/08/2006, 15h54   #2
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirect output to x-window in linux?

On Thu, 24 Aug 2006 14:11:51 GMT, Dave Farrance
<DaveFarrance@OMiTTHiSyahooANDTHiS.co.uk> wrote:
> Is it possible for a bash script to test it it's not running in a
> terminal and if that's the case, pop open an x-window of some sort (in
> linux) and redirect the output of the remaining commands in that script
> to the x-window?
>
> The test is easy enough: [ "$TERM" == "dumb" ]
>
> ...but I can't figure out how to redirect the output of the remaining
> script commands to an x-window.
>

To test whether the program is running under X, [ -n "$DISPLAY" ]
Otherwise, you can redirect output to a file or pipe it to mail.

{ do_this; do_that; etc; } | xterm -hold -e cat
If there is a lot of output, you can use less instead of cat, or use the
-sl and -sb options to xterm.

--
How do I type "for i in *.dvi do xdvi $i done" in a GUI?
-- Discussion in comp.os.linux.misc on the intuitiveness of interfaces
  Réponse avec citation
Vieux 24/08/2006, 18h50   #3
Dave Farrance
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirect output to x-window in linux?

Bill Marcum <bmarcum@iglou.com> wrote:

>On Thu, 24 Aug 2006 14:11:51 GMT, Dave Farrance wrote:
>> Is it possible for a bash script to test it it's not running in a
>> terminal and if that's the case, pop open an x-window of some sort (in
>> linux) and redirect the output of the remaining commands in that script
>> to the x-window?
>>

>To test whether the program is running under X, [ -n "$DISPLAY" ]
>Otherwise, you can redirect output to a file or pipe it to mail.
>
>{ do_this; do_that; etc; } | xterm -hold -e cat
>If there is a lot of output, you can use less instead of cat, or use the
>-sl and -sb options to xterm.


Looks good in principle, but doesn't work here for some reason. I tried:

{ echo 1; echo 2; } | xterm -hold -e cat

.... in both Mandriva 2006 and Ubuntu 6.06 and although the xterm window
opened, it remained completely blank.

--
Dave Farrance
  Réponse avec citation
Vieux 24/08/2006, 20h28   #4
Jon LaBadie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirect output to x-window in linux?

Dave Farrance wrote:
> Bill Marcum <bmarcum@iglou.com> wrote:
>
>> On Thu, 24 Aug 2006 14:11:51 GMT, Dave Farrance wrote:
>>> Is it possible for a bash script to test it it's not running in a
>>> terminal and if that's the case, pop open an x-window of some sort (in
>>> linux) and redirect the output of the remaining commands in that script
>>> to the x-window?
>>>

>> To test whether the program is running under X, [ -n "$DISPLAY" ]
>> Otherwise, you can redirect output to a file or pipe it to mail.
>>
>> { do_this; do_that; etc; } | xterm -hold -e cat
>> If there is a lot of output, you can use less instead of cat, or use the
>> -sl and -sb options to xterm.

>
> Looks good in principle, but doesn't work here for some reason. I tried:
>
> { echo 1; echo 2; } | xterm -hold -e cat
>
> ... in both Mandriva 2006 and Ubuntu 6.06 and although the xterm window
> opened, it remained completely blank.
>


mkfifo FIFO
xterm -hold -e 'cat FIFO' &
{commands generating data} > FIFO
  Réponse avec citation
Vieux 24/08/2006, 21h48   #5
Dave Farrance
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirect output to x-window in linux?

Jon LaBadie <jxlabadie@axcxmx.org> wrote:

>Dave Farrance wrote:
>> Looks good in principle, but doesn't work here for some reason. I tried:
>>
>> { echo 1; echo 2; } | xterm -hold -e cat
>>
>> ... in both Mandriva 2006 and Ubuntu 6.06 and although the xterm window
>> opened, it remained completely blank.

>
>mkfifo FIFO
>xterm -hold -e 'cat FIFO' &
>{commands generating data} > FIFO


Thanks. That's an improvement in that it works in Ubuntu 6.06, but not
in Mandriva 2006. Maybe I should update the latter to the Mandriva 2007
beta anyway.

--
Dave Farrance
  Réponse avec citation
Vieux 25/08/2006, 00h06   #6
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirect output to x-window in linux?

On 2006-08-24, Dave Farrance wrote:
> Is it possible for a bash script to test it it's not running in a
> terminal and if that's the case, pop open an x-window of some sort (in
> linux) and redirect the output of the remaining commands in that script
> to the x-window?
>
> The test is easy enough: [ "$TERM" == "dumb" ]
>
> ...but I can't figure out how to redirect the output of the remaining
> script commands to an x-window.


[ -t 0 ] || { xterm -e "$0" "$@"; exit; }
printf "%s " "${*:-Enter name: }"
read name


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 27/08/2006, 22h16   #7
Dave Farrance
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirect output to x-window in linux?

"Chris F.A. Johnson" <cfajohnson@gmail.com> wrote:

>On 2006-08-24, Dave Farrance wrote:
>> Is it possible for a bash script to test it it's not running in a
>> terminal and if that's the case, pop open an x-window of some sort (in
>> linux) and redirect the output of the remaining commands in that script
>> to the x-window?
>>
>> The test is easy enough: [ "$TERM" == "dumb" ]
>>
>> ...but I can't figure out how to redirect the output of the remaining
>> script commands to an x-window.

>
>[ -t 0 ] || { xterm -e "$0" "$@"; exit; }
>printf "%s " "${*:-Enter name: }"
>read name


Thanks. That works fine.

--
Dave Farrance
  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 13h02.


Édité par : vBulletin® version 3.7.3
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,16495 seconds with 15 queries