I'm having a few issues with FileUtils writing stuff to stderr when no
error has occurred. For example I might have the following simple
Rakefile:
require 'rake'
task :clean do
rm_rf 'test'
end
When I run
rake clean 2> err
In the err file I see:
'rm -rf test'
I would expect this to be sent to stdout rather than err.
The problem that I have is that I am trying to detect a rake failure
from within ant. Rake doesn't seem to return the correct error code so I
was testing for failure by detecting if anything was written to stderr.
My ant task would thus look something like this:
I'm having a few issues with FileUtils writing stuff to stderr when no error has occurred. For example I might have the following simple
Rakefile:
require 'rake'
task :clean do
rm_rf 'test'
end
Note that rake's rm_rf is not exactly FileUtils' rm_rf
When I run
rake clean 2> err
In the err file I see:
'rm -rf test'
I would expect this to be sent to stdout rather than err.
Why? I expect informational messages on stderr. This way rake's messages don't interfere with a rake user's output. By having rake's messages on stderr a rake task author can write tasks that can be piped to other commands.
rake email | sendmail # for example
(Yes, rake currently outputs a message on stdout. I have fixed that in trunk.)
The problem that I have is that I am trying to detect a rake failure from within ant. Rake doesn't seem to return the correct error code so I was testing for failure by detecting if anything was written to stderr.
You should query $?, not stderr. Rake should be behaving like a standard unix command.
I see your point. I should be able to check the return code for errors.
This would make the ant task even simpler as I would just have to set
the 'failonerror' flag.
I guess my question above was trying to find another way of doing this
because initially the return code was returning 0 when I was not
expecting it.
After reading your comments I've gone back to look at the code to see if
I could pinpoint where it was going wrong (you'll have to forgive me -
I'm new to ruby and am modifying a script written by someone else)
I traced the problem to a 'system' command. We are using a javascript
closure compiler to minify some javascript. It would fail if there was a
syntax error in the javascript - but the rake script would exit
normally. The original piece of code looked like:
system `#{JAVA_CMD} -jar #{JS_ROOT}/lib/compiler.jar --js=#{src}
--js_output_file=#{dst}`
and then the rake script carried on as normal. I then tried to capture
the $? of the command and raise an exception if it was non-zero.
Unfortunately, as it stands the above command always returns a non-zero
response. I eventually figured out that it was the back-ticks that was
causing the issue and so my final solution was to do this:
system("#{JAVA_CMD} -jar #{JS_ROOT}/lib/compiler.jar --js=#{src}
--js_output_file=#{dst}")
# Raise an exception if the compiler fails
if( !$?.success? )
raise "Closure Compiler failed to compile javascript"
end
I'm having a few issues with FileUtils writing stuff to stderr when no error has occurred. For example I might have the following simple
Rakefile:
require 'rake'
task :clean do
rm_rf 'test'
end
Note that rake's rm_rf is not exactly FileUtils' rm_rf
When I run
rake clean 2> err
In the err file I see:
'rm -rf test'
I would expect this to be sent to stdout rather than err.
Why? I expect informational messages on stderr. This way rake's messages don't interfere with a rake user's output. By having rake's messages on stderr a rake task author can write tasks that can be piped to other commands.
rake email | sendmail # for example
(Yes, rake currently outputs a message on stdout. I have fixed that in trunk.)
The problem that I have is that I am trying to detect a rake failure from within ant. Rake doesn't seem to return the correct error code so I was testing for failure by detecting if anything was written to stderr.
You should query $?, not stderr. Rake should be behaving like a standard unix command.