![]() |
Das unix Kommando "tee" - ein "T-Stück"
Hallo,
ich hatte gerade das Problem, dass ich eine log Datei mit der Ausgabe des dcc32.exe brauchte, aber auch nicht auf die Ausgabe auf dem Bildschirm verzichten wollte. Unter unix gibt es ein "tee" Kommando. "tee" gibt den Inhalt der Standardeingabe auf der Standardausgabe aus und speichert sie zusätzlich in einer Datei ab. Beisp:
Code:
Es wird das "dir" ausgeführt und zum einen direkt auf dem Bildschirm ausgegeben und gleichzeitig in die Datei c:\temp\dir.txt geschrieben.
dir | tee c:\temp\dir.txt
Es ist auch folgendes möglich:
Code:
Es wird das komplette "dir /b /s" ausgegeben, und danach das Ergebnis von find ;-)
dir /b /s | tee con | find "exe"
Der Dateiname con gibt nur an, das es auf der Console (also Bildschirm) ausgegeben werden soll.
Code:
Ich habe diese Funktionalität gebraucht und wollte nicht lange im Internet suchen.
<Befehl> | tee [-a] <Dateiname>
gibt die Ausgabe von <Befehl> auf dem Bildschirm aus und schreibt zusätzlich in die Datei <Dateiname> Mit dem Parameter -a wird die Datei nicht neu erzeugt, sondern der Text an die Datei angehängt. oder <Befehl 1> | tee con | <Befehl 2> gibt die Ausgabe von <Befehl 1> auf dem Bildschirm aus und gibt das Ergebnis zusätzlich an die Standardeingabe von <Befehl 2> weiter Es funktionieren auch die "<" und ">" Umleitungen tee [-a] <Dateiname 1> < <Dateiname 2> > <Dateiname 3> Datei <Dateiname 1> wird mit dem Inhalt von Datei <Dateiname 2> erzeugt und Datei <Dateiname 3> wird auch mit dem Inhalt von Datei <Dateiname 2> erzeugt. Also -> selberschreiben ! Das geht mit Delphi sehr einfach: Da es kein wirklich komplexes Programm ist, poste ich hier nur den Quellcode. ;-)
Delphi-Quellcode:
program tee;
{$APPTYPE CONSOLE} // tee: copy StdInput to StdOutput and TextFile // // usage: tee [-a] filename // -a appends to existing file (without -a tee overrides the old file) // // example: copy *.* c:\temp\*.* | tee c:\temp\copy.log // // For more information see (in german): // [url]http://www.delphipraxis.net/topic91571_das+unix+kommando+tee+ein+tstueck+beim+ausga.html[/url] // // (c) 2006, MaBuSE member of delphipraxis.net uses SysUtils; var s: string; f: TextFile; begin try // check parameters and open file if ParamCount=0 then begin WriteLn(ErrOutput, 'error: no parameter'); WriteLn(ErrOutput, 'tee [-a] filename'); Exit; end; if ParamStr(1) = '-a' then begin if ParamCount=1 then begin WriteLn(ErrOutput, 'error: not enough parameters'); WriteLn(ErrOutput, 'tee [-a] filename'); Exit; end; // append to file AssignFile(f, ParamStr(2)); Append(f); end else begin // create new file if file exist AssignFile(f, ParamStr(1)); ReWrite(f); end; // this loop does all the work while not eof(Input) do begin ReadLn(Input, s); WriteLn(Output, s); WriteLn(f, s); end; // close file handle CloseFile(f); except // my global exception handling :-) on E: Exception do begin WriteLn(ErrOutput, 'error: '+ E.Message); Exit; end; end; end. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:37 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz