If I write wget "no such address" -o "test.html" it first creates the test.html and in case of failure, leaves it empty. However, when not using -o, it will wait to see if the download succeeds and only after that, it'll write the file.

I'd like the latter behavior to be applied to -o too, is it possible?

link|improve this question

33% accept rate
feedback

2 Answers

The correct syntax is

wget "url" -O file

notice the UPPERCASE O. The -o options tells wget to write a log file, that's why it's always written even on failure.

link|improve this answer
At first I thought it was working, but then I found it didn't. try wget "host.does.not.exist"; -O "emptyFile" An error is returned, yet the emptyFile is created. – akurtser Jul 22 '10 at 9:38
@akurtser you're right. I think there's no way to tell wget not to create the file. I found this thread: mail-archive.com/wget@sunsite.dk/msg08586.html in which they discuss the matter. The baseline is that you can have MULTIPLE downloads to the same file so it gets created because wget cannot be shure that ALL urls will fail. – MrShunz Jul 22 '10 at 11:41
Well thanks, it's a part of a bash script I'm writing, so I'll just try to first save it a temp file, which in case of successful download, will be be renamed. Not very elegant, but can't think of anything better. – akurtser Jul 22 '10 at 12:19
@akurtser Surely you can check the return code from wget then... it should tell you if you can delete the file "if not found". So no need for temp/renaming. – MrShunz Jul 22 '10 at 12:42
feedback

Whoever wrote wget needs to get on the ball and fix that problem... I've been dealing with it for 4 years now and it's really getting on my nerves.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.