Thread STDOUT und ERROUT in Datei umleiten (22 answers)
Opened by Eng1958 at 2013-11-14 12:22

GwenDragon
 2015-03-27 17:08
#180429 #180429
User since
2005-01-17
14540 Artikel
Admin1
[Homepage]
user image
DIE Beste!

Code ohne Gewähr!


Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use strict;          
use warnings;        
use File::Compare;  

use Getopt::Long;

$| = 1;

sub help {
  print STDERR <<TXT;


Syntaxbeispiel:
  $0 -f1 datei1.txt -f2 datei2.txt -log log.log
  
TXT
  exit 255;
}

my $file1 = '';
my $file2 = '';
my $logdatei  = '';
my $help = 0;
GetOptions (
  'h|?'        => \$help,
  'log|logfile=s' => \$logdatei,
  'f1|file1=s' => \$file1,
  'f2|file2=s' => \$file2
);

help() if $help;

print "\x07### ERROR: Dateiname erste Datei fehlt" and help() if not length $file1;
print "\x07### ERROR: Dateiname zweite Datei fehlt" and help() if not length $file2;
print "\x07### ERROR: Dateiname Log-Datei fehlt" and help() if not length $logdatei;

my %exclude;
my $compare = compare($file1,$file2);

open my $fh1, '<', $file1 or die $!; 
while (<$fh1>) {
  chomp;             
  $exclude{$_}++;    
}
close $fh1;

open my $logfh, '>', $logdatei or die $!;


open my $fh2, '<', $file2 or die $!;  
while (<$fh2>) {
  chomp;            
  if($compare == 1){
      print $logfh "False! the files are not equal \n";
     
      print $logfh "$_\n" unless $exclude{$_}; 

  }
  elsif($compare == 0){  
             
    print $logfh "True! the Files are equal \n";
  }
}
close $fh2;

close $logfh;
die Drachin, Gwendolyn


Unterschiedliche Perl-Versionen auf Windows (fast wie perlbrew) • Meine Perl-Artikel

View full thread STDOUT und ERROUT in Datei umleiten