Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for tee.pl

(view source code of tee.pl as plain text)

  1. #! perl
  2.  
  3. # Store help text in a variable
  4. $syntax = "\nTee.pl,  Version 2.00\n";
  5. $syntax = $syntax."Display text on screen and redirect it to a file simultaneously\n\n";
  6. $syntax = $syntax."Usage:  some_command  \|  PERL.EXE  TEE.PL  filename\n\n";
  7. $syntax = $syntax."Where:  \"some_command\" is the command whose output should be redirected\n";
  8. $syntax = $syntax."        \"filename\"     is the file the output should be redirected to\n\n";
  9. $syntax = $syntax."Written by Rob van der Woude\nhttp://www.robvanderwoude.com\n";
  10.  
  11. # Display help and quit if no arguments were specified
  12. if ( !$ARGV[0] ) {
  13. 	print $syntax;
  14. 	exit(1);
  15. }
  16.  
  17. # Open file for writing, or display help text on error
  18. open( OUT, "> $ARGV[0]" ) || die( "\nCannot open file \"$ARGV[0]\"\n\n$syntax" );
  19.  
  20. # Read and redirect standard input
  21. while ( <STDIN> ) {
  22. 	print $_;
  23. 	print OUT $_;
  24. }
  25.  
  26. # Close output file
  27. close OUT;
  28.  

page last modified: 2024-04-16; loaded in 0.0063 seconds