Need a help in scripting

Hello Friends,
I am facing a problem in coding a certain thing and i am completely
unaware of it. The requirement is that…

When i am executing my ruby scripts through cmd, then after executing
the scripts an html report file is auto-generated which will have the
output of my ruby script.
For ex- If the scripts run fine than the html report will have a Passed
message
and
if the scripts failed than the html report will have the complete error
report of that script i.e which line got failed(as it is displayed in
cmd console).

You should use exception handling to get custom error messages.
Some code snippet or error message might help !

Could you try something like this?
Tell me if it has cleared up things now.

https://gist.github.com/abinoam/7489732

def the_main_script

Your main script

Do whatever here

x = rand(3)
puts “x = #{x}”
puts “and 10/#{x} = #{10/x}” # When x==0 ZeroDivisionError
end

begin
the_main_script
rescue => exception_detail
p exception_detail.inspect
p exception_detail.message
p exception_detail.backtrace
puts exception_detail.backtrace.join("\n")
else
puts “Everything went ok!”
end

Best regards,
Abinoam Jr.

i am trying but its not working, the script is not running and it is
unable to generate html report…
can u please help me with the code

Perhaps you can print debug messages to figure out where you are
encountering the problem.

Exceptional handling code goes like this:

begin
1/0
p ‘I should never get executed’
rescue
p ‘I am rescuing an exception and can do what I want!’
end

See a short blog about this:

http://www.skorks.com/2009/09/ruby-exceptions-and-exception-handling/


Gary

On Fri, Nov 15, 2013 at 7:53 PM, saurav panda [email protected]
wrote:

i am trying but its not working, the script is not running and it is
unable to generate html report…
can u please help me with the code

What code? I haven’t seen any so far. Until now I have to assume
this is an attempt to make other people do your (home-) work for free.

Regards

robert

Hi,

On 16 Νοε 2013, at 11:55 , Robert K. [email protected]
wrote:

On Fri, Nov 15, 2013 at 7:53 PM, saurav panda [email protected] wrote:

i am trying but its not working, the script is not running and it is
unable to generate html report…
can u please help me with the code

What code? I haven’t seen any so far. Until now I have to assume
this is an attempt to make other people do your (home-) work for free.

But I will share some code for I am kind (and just got back home from a
cocktail party, aha! )

#!/usr/bin/env ruby

Lazy module. Lyrics are released under MIT license

Figuring out the tune is left as an exercise to the

programmer

module Lazy
def self.print
“I was dreaming of rspec”
“and was failing at the test…”
“I began to lose control”
“I began to lose control”
“”
“I didn’t mean to release you”
“I’m sorry for the push request”
“Oh no, I didn’t want to upload you”
“I’m just a lazy guy”
“”
“I was feeling insecure”
“You might have buggy code in you”
“I was shivering inside”
“I was shivering inside”
“”
“I didn’t mean to release you”
“I’m sorry for the push request”
“Oh no, I didn’t want to upload you”
“I’m just a lazy guy”
“”
“I was handling your controlles”
“To avoid writing the tests”
“I was swallowing my pain”
“I was swallowing my pain!!!”
“”
“I didn’t mean to release you”
“I’m sorry for the push request”
“Oh no, I didn’t want to upload you…”
“I’m just a lazy guy…”
end
end

Regards

robert


remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Feel to free to modify and/or alternate the lyrics. I’m not a English
mother-tongue and also about to sleep on the keyboard, so if I made a
mistake somewhere please correct me!.

Cheers!

Panagiotis (atmosx) Atmatzidis

email: [email protected]
URL: http://www.convalesco.org
GnuPG ID: 0x1A7BFEC5
gpg --keyserver pgp.mit.edu --recv-keys 1A7BFEC5

Hey Saurav,

Maybe try something like the following?

def run_scripts
scripts = [path_to_script1, path_to_script2, …]

results = scripts.map { |cmd| system( cmd ) }

if results.all?
# output the “all scripts passed” html
else
# output the “uh-oh there was an error” html
end
end

Two tricks here:

  1. the “system” method runs the command in cmd and returns true if the
    command exited successfully, otherwise it returns false or nil
  2. the “all?” method is an array method that by default returns true
    if all array elements are true (“true” in the ruby sense), otherwise it
    returns false

So what happens is if any of the commands fail, the “all?” method
returns false and you can use that to know that there was an error

Hope this helps. Let us know how it goes…

Robert K. wrote in post #1127600:

On Fri, Nov 15, 2013 at 7:53 PM, saurav panda [email protected]
wrote:

i am trying but its not working, the script is not running and it is
unable to generate html report…
can u please help me with the code

What code? I haven’t seen any so far. Until now I have to assume
this is an attempt to make other people do your (home-) work for free.

Regards

robert

Robert i was asking only about generating a html report as i had no clue of doing
it. It not like making people work, I was asking for syntax… N do mind your
words that you are talking to others. n Yes u helped me alot about getting the
mindset of what type of people are there in this forum

Thanks
Saurav

Michael,

Thanks Bro,i got my hint from your script and i added some more
functionality to the script to make it work

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs