Ruby on rails 将输出重定向到stderr

Ruby on rails 将输出重定向到stderr,ruby-on-rails,ruby,redirect,stderr,Ruby On Rails,Ruby,Redirect,Stderr,我想将输出重定向到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 cas

我想将输出重定向到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”布尔值为false,我希望将输出重定向到stderr。怎样才能做到呢

既然您已经在处理shell,请在shell中执行:

function auth_tester {
  cd /data/$1/current && \
  bundle exec rake 'authentication:tester' >/dev/null 2>&1
  #                                 HERE:  ⇑⇑⇑⇑⇑⇑⇑⇑⇑⇑⇑⇑⇑⇑⇑
}
stderr
有一个
id=2
,我们正在将
stdout
重定向到
/dev/null
,并将
stderr
重定向到
stdout
,最终将其重定向到
/dev/null

要将
stdout
重定向到
stderr
,请使用相反的命令:

1>&2
要重定向ruby的输出,需要使用适当的接收器,并具有:


可以通过
print
put
将输出发送到
STDERR
。在这里,我选择发送到而不是,但这将适用于以下任一情况:

STDERR.puts 'my message here'
如果要更改Ruby脚本的退出状态(例如,显示脚本未成功完成),可以使用参数
false

exit(false)
要将输出发送到STDERR并返回不成功的退出状态,可以使用:




有关更多信息,请参阅honeybacker.io。

我的问题是如何将故障输出重定向到stderr。您的回答对于如何将stderr重定向到stdout也很有帮助。但请回答如何将我的失败输出重定向到stderr
exit(false)
abort 'my message here'