I want to redirect my output to stderr. I have a cron job
function auth_tester {
cd /data/$1/current && bundle exec rake 'authentication:tester' 1> /dev/null
}
which calls a rake task
namespace :authentication do
desc "Automatically runs authentication tester and notifies in case of failure"
task :tester => :environment do
auth_tester_results = AuthenticationTester.perform
exit(auth_tester_results.success? ? 0 : 1)
end
end
If the 'auth_tester_results' boolean is a false I want to redirect the output to stderr. How can it be done?
Since you are already dealing with shell, do it in shell:
stderr
has anid = 2
, and we are redirectingstdout
to/dev/null
, andstderr
tostdout
, eventually redirecting it to/dev/null
.To redirect
stdout
tostderr
, use the opposite:To redirect the output from ruby, one uses proper receiver with
IO#puts
: