Click here to get back home

why is return always 0?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
why is return always 0? jammer 03-16-2008
Posted by jammer on March 16, 2008, 8:45 pm
Please log in for more thread options
How do I make tftp fail if the host is bad?

my $rc = system( "/usr/bin/tftp bad$host < $tempFile 2>&1 >/
dev/null" );
if ( $rc != 0 ) {
print "unable to tftp to '$host'\n";
exit 1;
} else {
print "success: $rc\n";
}

Posted by sandy_saydakov on March 16, 2008, 9:10 pm
Please log in for more thread options
> How do I make tftp fail if the host is bad?
>
> my $rc = system( "/usr/bin/tftp bad$host < $tempFile 2>&1 >/dev/null"
);
> if ( $rc != 0 ) {
> print "unable to tftp to '$host'\n";
> exit 1;
> } else {
> print "success: $rc\n";
> }

Make sure the binary returns non-zero on failure. Try that command on
the command line and do "echo $?" right after.

-sandy
http://myperlquiz.com/

Posted by jammer on March 17, 2008, 3:56 pm
Please log in for more thread options
On Mar 16, 9:10 pm, sandy_sayda...@yahoo.com wrote:
>
> > How do I make tftp fail if the host is bad?
>
> > my $rc = system( "/usr/bin/tftp bad$host < $tempFile 2>&1
>/dev/null" );
> > if ( $rc != 0 ) {
> > print "unable to tftp to '$host'\n";
> > exit 1;
> > } else {
> > print "success: $rc\n";
> > }
>
> Make sure the binary returns non-zero on failure. Try that command on
> the command line and do "echo $?" right after.
>
> -sandyhttp://myperlquiz.com/

It prints an error when run interactively.
tftp does run, it just can't find the host.
It returns 0 because it ran, didn't work but it ran. :-(

Posted by sandy_saydakov on March 17, 2008, 4:49 pm
Please log in for more thread options
> > Make sure the binary returns non-zero on failure. Try that command on
> > the command line and do "echo $?" right after.
>
> It prints an error when run interactively.
> tftp does run, it just can't find the host.
> It returns 0 because it ran, didn't work but it ran. :-(

So there must be a bug in tftp then. It makes no sense to have a clean
exit code on failure.

For example, try it with 'ls':
> ls nonexistent
ls: nonexistent: No such file or directory
> echo $?
1
This makes perfect sense, doesn't it?

I would suggest trying a native TFTP Perl module:
http://search.cpan.org/~gsm/TFTP-1.0b3/TFTP.pm

/sandy
http://myperlquiz.com/

Posted by hymie! on March 18, 2008, 9:12 am
Please log in for more thread options
In our last episode, the evil Dr. Lacto had captured our hero,
sandy_saydakov@yahoo.com, who said:
>> > Make sure the binary returns non-zero on failure. Try that command on
>> > the command line and do "echo $?" right after.
>>
>> tftp does run, it just can't find the host.
>> It returns 0 because it ran, didn't work but it ran. :-(
>
>So there must be a bug in tftp then. It makes no sense to have a clean
>exit code on failure.

The fact that the host does not exist does not necessarily mean that
the tftp program failed, thus the 0 exit code.

eric-x% nslookup fuzzy
Server: 205.196.81.2
Address: 205.196.81.2#53

** server can't find fuzzy: NXDOMAIN

eric-x% echo $?
0
eric-x% finger hymie
finger: hymie: no such user.
eric-x% echo $?
0
eric-x%


--hymie! http://lactose.homelinux.net/~hymie hymie@lactose.homelinux.net
------------------------ Without caffeine for 504 days ------------------------

Similar ThreadsPosted
windows program return values vs perl return values from a call to system() -- windows post only October 29, 2005, 6:22 pm
return value October 7, 2005, 3:57 am
Help with 'system' seeming to return too soon... September 13, 2004, 2:08 pm
FAQ: How come exec() doesn't return? October 9, 2004, 5:10 pm
FAQ 8.2 How come exec() doesn't return? March 11, 2005, 12:03 am
=~ return value ? boolean ? May 17, 2005, 3:29 am
FAQ 8.2 How come exec() doesn't return? May 31, 2005, 11:03 pm
return and undef October 4, 2005, 8:35 am
FAQ 8.2 How come exec() doesn't return? October 8, 2005, 4:03 am
strange return value October 18, 2005, 1:14 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap