thor has asked for the wisdom of the Perl Monks concerning the following question:

Greetings fellow monks,
I'm trying to write a tool that changes a specific user's password on many Sybase databases across our environment. The problem that I'm running into is that when I call sp_password from within perl, it outputs it's normal output, whereas I would like to test the return value of sp_password and display it in cannonical form. Allow me to demonstrate:

$sth = $dbh->do(qq(sp_password $sa_password, $new_password, $user)) or + die "Couldn't set password on $server\n";

What this is currently doing is printing this
Password correctly set.
when I actually want it to print nothing, allow me to test for success or failure, and print "SUCCESS" or "FAILURE" accordingly. Any suggestions?

Replies are listed 'Best First'.
Re: Avoiding Output in DBI
by mpeppler (Vicar) on Jan 18, 2002 at 06:48 UTC
    User trs80 is correct - use the syb_err_handler attribute to set an error handler that ignores "errors" with an error code of 0 (that's what PRINT statements come back as.)

    Something like this should work:

    sub err_hdl { my($err, $sev, $state, $line, $server, $proc, $msg) = @_; if(!$err) { return 0; } return 1; } $dbh = DBI->connect(...., {syb_err_handler => \&err_hdl}); etc.

    Michael

Re: Avoiding Output in DBI
by trs80 (Priest) on Jan 18, 2002 at 05:55 UTC
    I don't have Sybase to test this on, but have you tried the
    syb_err_handler method in the DBD::Sybase module?
    It is possible that the output is being sent to standard
    error so the variable isn't getting any values.
    It could also be that a prepare - execute might work better
    for this command. I have a had similar instances working with
    MySQL.
Re: Avoiding Output in DBI
by screamingeagle (Curate) on Jan 18, 2002 at 07:26 UTC
    how about this :
    $sth = $dbh->do(qq(sp_password $sa_password, $new_password, $user)) or + die $dbh->errstr;
    hth... :)