2016-12-29 94 views
1

我想将输出重定向到stderr。我有一个cron作业将输出重定向到stderr

function auth_tester { 
    cd /data/$1/current && bundle exec rake 'authentication:tester' 1> /dev/null 
} 

它调用rake任务

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 

如果“auth_tester_results”布尔是假的我想将输出重定向到stderr。如何做呢?

回答

3

既然你已经与外壳处理,这样做在外壳:

function auth_tester { 
    cd /data/$1/current && \ 
    bundle exec rake 'authentication:tester' >/dev/null 2>&1 
    #         HERE: ⇑⇑⇑⇑⇑⇑⇑⇑⇑⇑⇑⇑⇑⇑⇑ 
} 

stderrid = 2,我们重定向到stdout/dev/null,并stderrstdout,最终将其重定向到/dev/null

重定向stdoutstderr,使用相反:

1>&2 

重定向从红宝石输出,一个使用适当的接收机IO#puts

$stderr.puts "Goes to stderr" 
+0

我的问题是如何将重定向我的失败输出到stderr。您的回答对于如何将stderr重定向到stdout也很有帮助。但请回答如何将我的故障输出重定向到stderr – krishna

+0

请参阅更新。 – mudasobwa

相关问题