Ruby behaves differently in windows task scheduler
Ruby won't recognize directories when run from the task scheduler. I've had similar issues with ruby when running from the windows task scheduler.
Can anyone explain why ruby behaves this way when run from the Windows Task Scheduler?
Consider the following directory on my desktop
(d)test
----(d)One ----(d)Two ----(d)Three ----(f)dirs.rb ----(f)log.log
(d) = Directory (f) = file
开发者_Python百科Consider the following Ruby script.
require 'logger'
log = Logger.new("C:/Users/crosson.Z7NETWORKS/Desktop/test/log.log", 'daily')
log.level = Logger::INFO
Dir.new("C:/Users/crosson.Z7NETWORKS/Desktop/test").each do |file|
log.info "%7s a dir? %s" % [file, File.directory?(file)]
end
Below is a result of the log when run from the command line.
I, [2011-08-30T12:50:47.700617 #5356] INFO -- : . a dir? true
I, [2011-08-30T12:50:47.700617 #5356] INFO -- : .. a dir? true
I, [2011-08-30T12:50:47.700617 #5356] INFO -- : dirs.rb a dir? false
I, [2011-08-30T12:50:47.700617 #5356] INFO -- : log.log a dir? false
I, [2011-08-30T12:50:47.700617 #5356] INFO -- : One a dir? true
I, [2011-08-30T12:50:47.700617 #5356] INFO -- : Three a dir? true
I, [2011-08-30T12:50:47.701617 #5356] INFO -- : Two a dir? true
Below is a result of the log when run from the task scheduler
I, [2011-08-30T13:03:07.187316 #5972] INFO -- : . a dir? true
I, [2011-08-30T13:03:07.188316 #5972] INFO -- : .. a dir? true
I, [2011-08-30T13:03:07.188316 #5972] INFO -- : dirs.rb a dir? false
I, [2011-08-30T13:03:07.188316 #5972] INFO -- : log.log a dir? false
I, [2011-08-30T13:03:07.188316 #5972] INFO -- : One a dir? false
I, [2011-08-30T13:03:07.188316 #5972] INFO -- : Three a dir? false
I, [2011-08-30T13:03:07.188316 #5972] INFO -- : Two a dir? false
Notice that my directories, One, Two and Three are no longer considered directories. What gives?
This is a complete guess, but what user is the Windows Task Scheduler using to run the script? I dimly remember issues with the task scheduler due to that process not having the same constellation of rights as me.
精彩评论