Just fyi, notepad may not be able to handle unix lineends, wordpad does it just fine, so no reason to download a program just to view a file. UltraEdit is one fine piece of software when it comes to the more advanced stuff though.
| [reply] |
I NOT INTENDED download files at all! All I need is view log.txt via MSIE web browser. I want it be formatted slightly --just separated as in my example.
| [reply] |
Easy does it, my friend. Just because it isn't in direct relation to your original question does not mean it may not be of use to radiantmatrix or someone else at some point. I was merely adding a small point, no need to get upset.
| [reply] |
Yes, I use ms Windows, IE6.0 browser to view logs. I view logs via browser, just type path to log file
http://www. domain.com/logs.txt This is most convenient for me, no other methods required. What should be corrected in code and how? Thanks. | [reply] |
Well, hold on there, friend -- no need to get punchy. You might have mentioned that you had this problem in your browser, and not in an editor: this is why it's important to be complete when asking a question, here.
To fix this code-side rather than client-side, you need to instruct your code to use Windows-style line endings. In your code, wherever you see "\n", use "\r\n" instead. If there are a great number of places that you've already used "\n" and you don't want to hunt them down, you could also use a short Perl script to convert them right before viewing. This might look like:
#!/usr/bin/perl
use strict;
use CGI::Simple;
my $q = new CGI::Simple;
$| = 1;
print $q->header(
-type => 'text/plain',
-expires => '+1m'
);
## the header is for plain text, and the data expires in 1m
## If there's no file parameter, exit with an error message
unless ($q->param('file')) {
print 'No File was requested';
exit;
}
open LOG, '<', $q->param('file') or do {
# exit with error if we can't open the file
print 'Unable to open file ',$q->param('file'),':',$!;
exit;
};
while (<LOG>) {
s{(\r\n)|(\n)}{\r\n}g; ## replace unix with Win line-endings
print $_;
}
This is untested
This should be invoked as http://www.domain.com/myname.pl?file=logs.txt (if you named your script 'myname.pl').
The Eightfold Path: 'use warnings;', 'use strict;', 'use diagnostics;', perltidy, CGI or CGI::Simple, try the CPAN first, big modules and small scripts, test first.
| [reply] [d/l] |