STDOUT is nil when rake task is run via cron

I have a simple rake script which looks like this

task :test => :environment do
response = %x{date}
puts 1
puts response
puts 2
end

When I run this directly from the command line, I get the correct
output.

However, when I call this rake task from cron, it gives me:

1

2

as the output.

What am I missing here? STDOUT seems to be written as nil or empty
string. Why is this happening?

Cron may have a different PATH set than the user account. It’s
possible that date isn’t in that PATH. In this case the string
would be null, and a command not found message would be sent to
STDERR.

You can confirm this by replacing ‘date’ with ‘which date’ in your
task above and then looking at the resulting output.

Shawn

I tried “which date” and I still get nil?

Im really stumped on this one. It seems like this behavior has got to be
happening to other people as well, weird.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs