View Single Post
Old 30th March 2009
diw's Avatar
diw diw is offline
Port Guard
 
Join Date: Jul 2008
Posts: 45
Default

Quote:
Originally Posted by drhowarddrfine View Post
Will the print part of your code try and print anything if there is nothing fetched by wget? I don't recall if wget just creates a file of zero length when it saves it.
I tried to wget a non-existent file and it creates a 0 byte file with the name from the -0 switch.
I suspect (I don't print on Windows much) that it will try to print this. In fact I am sure of it.

Perhaps the biggest limitation of the Windows CLI is it is not complex enough to manipulate output streams in more than one way at a time.
For instance, to check the output of a tracert (traceroute) for a string is trivial. To also redirect that stream to a file is not. Of course the solution in that case is to redirect the stream to a file first and then look for the string in the file. :]
In the case of wget it does not write error messages (e.g. "404 Not Found") to the file.
As I said, I am new to wget and the documentation is ... well ...
I will have a better look later.

Still, the cheap and dirty solution is to let wget run and then test the file. :]
Code:
wget -O filename http://www.nowhere.net/nothing.html
findstr ".*" filename && goto COOL
type error_message && exit
:COOL
type filename && exit
Of course again, substitute "print" for "type".
In this case there is a ready to go error_message file.
findstr ".*" - look for any character repeated any number of times.
Something nicer would be to store the URI as a variable and to append/prepend it as a footer/header on the error_message. Simple to do.

Keep me updated. I like writing batch files.

Best wishes.
Reply With Quote