PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Bash: stdout von sich selbst umleiten



yankee42
15-07-2008, 13:15
Hi @ll,
ich würde gerne in einem Script die Ausgabe von sich selbst umleiten. Zur Verdeutlichung:

if [ $# -eq 0 ]; then
$0 -foobar | osd_cat --font="-adobe-helvetica-bold-*-*-*-34-*-*-*-*-*-*-*" --shadow=2 2>&1
exit
fi;
echo "Hello"
sleep 1
echo "Again"

Wenn man dieses Script (ohne Argumente natürlich) ausführt, dann leitet es alle Ausgaben an osd_cat weiter.
Aber es gibt doch bestimmt eine bessere Methode anstatt sich selbst wieder mit anderem stdout aufzurufen, oder?

ContainerDriver
15-07-2008, 13:26
Hallo,

ich weiß jetzt nicht so genau was du meinst, aber suchst du vielleicht die Möglichkeit Funktionen zu bilden? Also etwa so:


func()
{
echo "Ausgabe von func";
}

func | xosd_cat [...]

yankee42
15-07-2008, 14:21
Actually I was thinking of some kind of command to change my stdout. Something like

setStdout osd_cat ...

In expect you can do something like that with the spawn-command. But I think that something like that should be possible without expect.

But I am happy with the usage of the function as well. I did not know that it is possible to pipe the output of a function somewhere else. Though there ist still one problem with it. Consider this script:

#!/bin/bash
func()
{
echo "Hello"
sleep 1
echo "Again"
}

func | osd_cat --font="-adobe-helvetica-bold-*-*-*-34-*-*-*-*-*-*-*" --shadow=2 2>&1

It works as I expected it to work in the begining, but unfortunatelly this script will never terminate and the letters will never disappear from the screen. I guess that the output in a function does not contain an eof-char which tells osd_cat that there is no more input and thus osd_cat tries to keep reading from a source that won't output any more data.
How can I fix this? Can I emit an eof manually?

EDIT: Ähm... Mir fällt gerade auf, dass ich alles auf englisch geschrieben habe. Das war eigentlich keine Absicht, ich hab nur irgendwie nicht drüber nachgedacht... Ich denke mal jeder versteht es trotzdem?!

ContainerDriver
15-07-2008, 15:02
Well, it works for me ;)

Also bei mir geht es so, d.h. osd_cat beendet sich nach kurzer Wartezeit selber... welche Version von osd_cat bzw. bash hast du denn?

yankee42
15-07-2008, 15:10
Also bei mir geht es so, d.h. osd_cat beendet sich nach kurzer Wartezeit selber... welche Version von osd_cat bzw. bash hast du denn?
Bash: 3.2-61
xosd: 2.2.12-113

*komisch* *nochmal probier*
*Wunder* Jetzt geht's.... aber eben... eben... Naja ok... Vielleicht war ich eben einfach zu blöd...

EDIT:
Es passiert immernoch manchmal. Aber ich kann keine Logik dahinter erkennen...