diff --git a/Repositories/otago_eprints3/otago_eprints/cfg/cfg.d/twitter.pl b/Repositories/otago_eprints3/otago_eprints/cfg/cfg.d/twitter.pl index cf3f4b4..b124706 100755 --- a/Repositories/otago_eprints3/otago_eprints/cfg/cfg.d/twitter.pl +++ b/Repositories/otago_eprints3/otago_eprints/cfg/cfg.d/twitter.pl @@ -13,6 +13,7 @@ my $isgdCmd = ''; my $twitterCmd = ''; + my $urlCmd = ''; my $shorturl = ''; my $title = $eprint->get_value( "title" ); @@ -24,25 +25,29 @@ SWITCH: foreach ( 'curl', 'wget' ) # add others here and below { - # Try to call the command, if it's not in the path then $? - # will be -1 and $! will be 'No such file or directory'. - # If nothing works, just fail silently. - system( $_ ); - if ( $? != -1 ) + # NJS 2010-01-12: Changed to use which instead of $? value. + # Check that the command exists using which. If it exists + # then the output of which will start with '/', otherwise + # it won't (it will usually be empty or something like + # "no such ..." or "foo: not found") + $urlCmd = `which $_`; + chomp $urlCmd; + + if ( $urlCmd =~ m|^/| ) { if ( /curl/ ) { - $isgdCmd = "curl --silent 'http://is.gd/api.php?longurl=" . $eprint->get_url . "'"; + $isgdCmd = "$urlCmd --silent 'http://is.gd/api.php?longurl=" . $eprint->get_url . "'"; $shorturl = `$isgdCmd`; - $twitterCmd = "curl --silent --basic --user $twitter_username:$twitter_password --data status='$title - $shorturl' http://twitter.com/statuses/update.xml"; + $twitterCmd = "$urlCmd --silent --basic --user $twitter_username:$twitter_password --data status='$title - $shorturl' http://twitter.com/statuses/update.xml"; `$twitterCmd &`; last SWITCH; } if ( /wget/ ) { - $isgdCmd = "wget --quiet --output-document=- 'http://is.gd/api.php?longurl=" . $eprint->get_url . "'"; + $isgdCmd = "$urlCmd --quiet --output-document=- 'http://is.gd/api.php?longurl=" . $eprint->get_url . "'"; $shorturl = `$isgdCmd`; - $twitterCmd = "wget --quiet --http-user=$twitter_username --http-password=$twitter_password --post-data='status=$title - $shorturl' http://twitter.com/statuses/update.xml"; + $twitterCmd = "$urlCmd --quiet --http-user=$twitter_username --http-password=$twitter_password --post-data='status=$title - $shorturl' http://twitter.com/statuses/update.xml"; `$twitterCmd &`; last SWITCH; }