Parcourir la source

Made watchdump.pl work on Windows (hopefully)

Alois Mahdal (@azzgoat) il y a 11 ans
Parent
révision
3a0d69344c
3 fichiers modifiés avec 11 ajouts et 5 suppressions
  1. 0
    2
      README.md
  2. 0
    1
      TODO.md
  3. 11
    2
      bin/watchdump.pl

+ 0
- 2
README.md Voir le fichier

87
 For improved visual feedack, it will pre-pend the file contents with the file
87
 For improved visual feedack, it will pre-pend the file contents with the file
88
 path and an "animation".  Display of the header can be controlled by options,
88
 path and an "animation".  Display of the header can be controlled by options,
89
 see `--usage`.
89
 see `--usage`.
90
-
91
-Note: Currently works only on UNIX-like systems.

+ 0
- 1
TODO.md Voir le fichier

5
         * mksheet.pl
5
         * mksheet.pl
6
         * htlogr: implement severities
6
         * htlogr: implement severities
7
         * htlogr: straighten up parameters
7
         * htlogr: straighten up parameters
8
-        * watchdump.pl: make it work on Windows
9
 
8
 
10
     * document:
9
     * document:
11
         * usage of mksheet.pl
10
         * usage of mksheet.pl

+ 11
- 2
bin/watchdump.pl Voir le fichier

35
     return $frame;
35
     return $frame;
36
 }
36
 }
37
 
37
 
38
+sub clear {
39
+    system "cls"    if -d "c:\\windows";
40
+    system "clear"  if -f "/bin/ls";
41
+}
42
+
38
 my $file = shift @ARGV or &usage;
43
 my $file = shift @ARGV or &usage;
39
 
44
 
40
 while (1) {
45
 while (1) {
41
-    system("clear");
46
+    &clear;
42
     printf "[%s] watching: %s\n%s\n", &get_frame(), $file, "=" x 80
47
     printf "[%s] watching: %s\n%s\n", &get_frame(), $file, "=" x 80
43
         unless $opts->{no_header};
48
         unless $opts->{no_header};
44
-    print `cat $file`;
49
+    if (open my $fh, "<", $file) {
50
+        print join "", <$fh>;
51
+        close $file;
52
+    } else { warn "cannot open $file: $!\n"; next; }
53
+} continue {
45
     sleep $opts->{delay};
54
     sleep $opts->{delay};
46
 }
55
 }