Jonathan Nichols ([EMAIL PROTECTED]) scribbled:
> (Note: I suck at Perl.)
> 
> I have a script. it's a simple script.
> 
> #!/usr/bin/perl
> $file = "foo.txt";
> system"wget http://clutter.pbp.net/~jnichols/foo.txt"; || die "Couldn't 
> get $file";
> 
> Currently "foo.txt" doesn't exist. It'll return a 404. It doesn't die 
> with the error message above. Basically, I need wget to die and return 
> the specified error message if the result is *anything* but successful. 
> If wget gets the file, ok. If it fails to get the file for any reason, 
> barf out.

This is a trimmed down version of a sub I use for system calls:

#########################################
        $command = 'wget http://clutter.pbp.net/~jnichols/foo.txt';
   system("$command") == 0
      or die "system $command failed: $?";
   if ($? == -1) {
       print "failed to execute: $!\n";
   }
   elsif ($? & 127) {
       printf "child died with signal %d, %s coredump\n",
           ($? & 127),  ($? & 128) ? 'with' : 'without';
   }
#########################################

It should work for your situation.  I think I got it out of one of the
O'Reilly books.

hth,

Cooper.
--
[email protected] mailing list

Reply via email to