# STDOUT is nil when rake task is run via cron

**URL:** <https://www.ruby-forum.com/t/stdout-is-nil-when-rake-task-is-run-via-cron/121859>\
**Category:** Deployment\
**Created:** [December 2, 2007, 1:30am UTC](https://www.ruby-forum.com/t/stdout-is-nil-when-rake-task-is-run-via-cron/121859 "2007-12-02T01:30:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [December 2, 2007, 1:30am UTC](https://www.ruby-forum.com/t/stdout-is-nil-when-rake-task-is-run-via-cron/121859/1 "2007-12-02T01:30:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [December 2, 2007, 4:42am UTC](https://www.ruby-forum.com/t/stdout-is-nil-when-rake-task-is-run-via-cron/121859/2 "2007-12-02T04:42:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [December 18, 2007, 8:56pm UTC](https://www.ruby-forum.com/t/stdout-is-nil-when-rake-task-is-run-via-cron/121859/3 "2007-12-18T20:56:02Z")

</div>

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.
