Hi, I''ve a Rails application who starts a Ruby script . The script is made via Web -> database. Than you can select a script to start via a database list. Problem: In case of errors , I like to start a rescue showing the users the problems. render(:text => "<pre>" + CGI::escapeHTML(` 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>") Rescue don''t work in this case, how can I check syntax errors? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 11/2/06, lucevers <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > > I''ve a Rails application who starts a Ruby script . > The script is made via Web -> database. > Than you can select a script to start via a database list. > > Problem: > > In case of errors , I like to start a rescue showing the users the > problems. > > > render(:text => "<pre>" + CGI::escapeHTML(` > 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>") > > > Rescue don''t work in this case, how can I check syntax errors?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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 ? On 11/2/06, Jeremy Evans <jeremyevans0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 11/2/06, lucevers <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > Hi, > > > > I''ve a Rails application who starts a Ruby script . > > The script is made via Web -> database. > > Than you can select a script to start via a database list. > > > > Problem: > > > > In case of errors , I like to start a rescue showing the users the > > problems. > > > > > > render(:text => "<pre>" + CGI::escapeHTML(` > > 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>") > > > > > > Rescue don''t work in this case, how can I check syntax errors? > > 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 > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---