a b wrote: > > I am trying to fetch various docs from server using wget. Below is the code > Files are downloading but of 0 size :( > > Am i missing any thing > > [EMAIL PROTECTED]:~/adave> cat fetch.pl > open(S,"<./source.txt") || die "Failed to open file 'source.txt' $!"; > while(<S>) > { > > if (/http/) > { > @a=split(/\//,$_); > $file=$a[-1]; > $r=exec `/usr/bin/wget $_ >./$file `; > print $r; > print "Printing the output of last $?"; > exit; > } > } > close(S); > [EMAIL PROTECTED]:~/adave> perl fetch.pl > --18:03:19-- http://localhost/training_files/docs/overview.ppt > => `overview.ppt' > Resolving localhost... x.x.x.x. > Connecting to localhost x.x.x.x... connected. > HTTP request sent, awaiting response... 200 OK > Length: 145,920 [application/vnd.ms-powerpoint] > > 100%[==================================================================================================================>] > 145,920 81.61K/s > > 18:03:21 (81.43 KB/s) - `overview.ppt' saved [145920/145920] > > 0Printing the output of last [EMAIL PROTECTED]:~/adave> ls -l > total 5 > -rw-r--r-- 1 adave aix 254 2008-07-22 17:48 fetch.pl > -rw-r--r-- 1 adave aix 4074 2008-07-22 16:52 source.txt > -rw-r--r-- 1 adave aix 0 2008-07-22 18:03 overview.ppt > > > > Thanks, > a b
The URLs from your file still have newlines at the end, so you are issuing two commands: /usr/bin/wget $_ >./$file As far as I know wget doesn't write its output to stdout anyway, so it should work as it is without the output redirection. Why not do the whole thing in native Perl anyway, as below. HTH, Rob use strict; use warnings; use LWP::Simple; open my $fh, '<', './source.txt' or die "Failed to open file 'source.txt' $!"; while (<$fh>) { chomp; next unless /^http:/; my $file = (split m|/|)[-1]; my $resp = getstore($_, $file); print "$file - $resp\n"; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/