2016-12-29 93 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

相關問題