Просмотр исходного кода

Made watchdump.pl work on Windows (hopefully)

Alois Mahdal (@azzgoat) 13 лет назад
Родитель
Сommit
3a0d69344c
3 измененных файлов: 11 добавлений и 5 удалений
  1. 0
    2
      README.md
  2. 0
    1
      TODO.md
  3. 11
    2
      bin/watchdump.pl

+ 0
- 2
README.md Просмотреть файл

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 Просмотреть файл

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 Просмотреть файл

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
 }