Rescue don't work on web applications

You are using the backtick operator improperly. Basically, you are doing this:

render(:text => "<pre>" + CGI::escapeHTML(IO.popen("
         begin
          /home/luc/radrails/cpe/public/startq_test.rb #{syntf.path}
          rescue
NoMethodError,SyntaxError,NameError,StandardError,SystemExit,ScriptError
=> snfault
          fltlog = File.open("/test/result/script.log", "w")
          fltlog.puts "#{snfault}"
          fltlog.close
         end

         ").read) + "</pre>")

which executes your shell with "begin
/home/luc/radrails/cpe/public/startq_test.rb ...". Since you are
trying to execute ruby code in the shell, you lose.

Something like this may work, though:

render(:text => "<pre>" + CGI::escapeHTML(eval("
         begin
          /home/luc/radrails/cpe/public/startq_test.rb #{syntf.path}
          rescue
NoMethodError,SyntaxError,NameError,StandardError,SystemExit,ScriptError
=> snfault
          fltlog = File.open("/test/result/script.log", "w")
          fltlog.puts "#{snfault}"
          fltlog.close
         end

         ")) + "</pre>")

Make sure you check the values of syntf.path and snfault carefully
before doing that.

Jeremy

Jeremy

Thanks for your solution I’ll test this.
But I also did a lot of other checks:

If you start via cli a Ruby script with the next info:

begin
eval("#{fquery}")

rescue SyntaxError,NameError,StandardError => snfault
fltlog.puts “#{snfault}” -> put result in a file
end


Method: In case of a bug via rescue a log file has all the information.

When you put a syntax fault in fquery: example -> pust “test” (puts) everything works in CLI.
You get the log file.
But if you start the same script via a Ruby on Rails controller you don’t get de result = log file.

I did several tests and I’m sure that ‘rescue’ don’t work via ruby on Rails controller. (starting an external script)
Is it a bug ?