From 1069cb7c485d2e30da8c244f3c33b90dcc461a33 Mon Sep 17 00:00:00 2001 From: tma Date: Thu, 15 Apr 2010 07:29:37 +0800 Subject: [PATCH] fix STDERR output redirection to file to append instead of overwrite. --- .../outputs/cron/output_redirection.rb | 12 ++++++++--- test/output_redirection_test.rb | 20 +++++++++---------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/whenever/outputs/cron/output_redirection.rb b/lib/whenever/outputs/cron/output_redirection.rb index 34dd2f8..ee15030 100644 --- a/lib/whenever/outputs/cron/output_redirection.rb +++ b/lib/whenever/outputs/cron/output_redirection.rb @@ -32,11 +32,17 @@ module Whenever def redirect_from_hash case when stdout == '/dev/null' && stderr == '/dev/null' - ">> /dev/null 2>&1" + "> /dev/null 2>&1" + when stdout && stderr == '/dev/null' + ">> #{stdout} 2> /dev/null" when stdout && stderr - ">> #{stdout} 2> #{stderr}" + ">> #{stdout} 2>> #{stderr}" + when stderr == '/dev/null' + "2> /dev/null" when stderr - "2> #{stderr}" + "2>> #{stderr}" + when stdout == '/dev/null' + "> /dev/null" when stdout ">> #{stdout}" else diff --git a/test/output_redirection_test.rb b/test/output_redirection_test.rb index cb5d00f..807582e 100644 --- a/test/output_redirection_test.rb +++ b/test/output_redirection_test.rb @@ -46,7 +46,7 @@ class OutputRedirectionTest < Test::Unit::TestCase end should "output the command without the log syntax appended" do - assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2> dev_err$/, @output + assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, @output end end @@ -80,7 +80,7 @@ class OutputRedirectionTest < Test::Unit::TestCase should "output the command with the overridden redirection syntax appended" do assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output - assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2> dev_err$/, @output + assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, @output end end @@ -130,7 +130,7 @@ class OutputRedirectionTest < Test::Unit::TestCase end should "output the command without the redirection syntax appended" do - assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2> dev_err$/, @output + assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, @output end end @@ -145,8 +145,8 @@ class OutputRedirectionTest < Test::Unit::TestCase file end - should "output the command without the standard errror syntax appended" do - assert_match /^.+ .+ .+ .+ blahblah 2> dev_null$/, @output + should "output the command without the standard error syntax appended" do + assert_match /^.+ .+ .+ .+ blahblah 2>> dev_null$/, @output end end @@ -177,7 +177,7 @@ class OutputRedirectionTest < Test::Unit::TestCase end should "output the command without the log syntax appended" do - assert_match /^.+ .+ .+ .+ blahblah 2> dev_err$/, @output + assert_match /^.+ .+ .+ .+ blahblah 2>> dev_err$/, @output end end @@ -207,7 +207,7 @@ class OutputRedirectionTest < Test::Unit::TestCase end should "output the command with stdout directed to /dev/null" do - assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null$/, @output + assert_match /^.+ .+ .+ .+ blahblah > \/dev\/null$/, @output end end @@ -237,7 +237,7 @@ class OutputRedirectionTest < Test::Unit::TestCase end should "output the command with stderr directed to /dev/null" do - assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null 2>&1$/, @output + assert_match /^.+ .+ .+ .+ blahblah > \/dev\/null 2>&1$/, @output end end @@ -267,7 +267,7 @@ class OutputRedirectionTest < Test::Unit::TestCase end should "output the command with stderr directed to /dev/null" do - assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null 2> my_error.log$/, @output + assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null 2>> my_error.log$/, @output end end @@ -286,4 +286,4 @@ class OutputRedirectionTest < Test::Unit::TestCase assert_match /^.+ .+ .+ .+ blahblah >> cron.log 2>&1$/, @output end end -end \ No newline at end of file +end