Calling another Ruby script

P

Peter Bailey

Hi,
Can someone please tell me how you can can call out another Ruby script?
I have a lot of image processing scripts. Sometimes, rarely, they'll
simply fail because some of the images might be bad. But, I need to know
whether or not the images got processed or not. So, because an image
failure can literally lead to the whole Ruby script just failing, I'd
like to create a separate script that simply lists all of the files in
the input directory (separately from the processing script) and checks
to see if they all got processed or not. In DOS, I would use a "call"
statement. What's the equivalent in Ruby?
Thanks,
Peter
 
T

Tim Hunter

Peter said:
Hi,
Can someone please tell me how you can can call out another Ruby script?
I have a lot of image processing scripts. Sometimes, rarely, they'll
simply fail because some of the images might be bad. But, I need to know
whether or not the images got processed or not. So, because an image
failure can literally lead to the whole Ruby script just failing, I'd
like to create a separate script that simply lists all of the files in
the input directory (separately from the processing script) and checks
to see if they all got processed or not. In DOS, I would use a "call"
statement. What's the equivalent in Ruby?
Thanks,
Peter

system("ruby myscript.rb")
 
R

Robert Klemme

2009/8/10 Peter Bailey said:
I have a lot of image processing scripts. Sometimes, rarely, they'll
simply fail because some of the images might be bad. But, I need to know
whether or not the images got processed or not. So, because an image
failure can literally lead to the whole Ruby script just failing, I'd
like to create a separate script that simply lists all of the files in
the input directory (separately from the processing script) and checks
to see if they all got processed or not.

I am not sure I understand the requirement from this. Why do you need
a separate script? What stops you from invoking a method in the same
script that does the check?

Kind regards

robert
 
P

Peter Bailey

Robert said:
I am not sure I understand the requirement from this. Why do you need
a separate script? What stops you from invoking a method in the same
script that does the check?

Kind regards

robert

This second script is the one that's doing the check. The first script
needs to process the images, meaning, it converts them to various other
formats. And, if the image processing fails (it's calling an outside
image processing utility), then, the whole Ruby script can simply fail,
too. If I have 50 files coming in, then, I'll need to know whether or
not those 50 files went to their proper destinations in their proper
formats. If the image processing fails for any reason, and the Ruby
script simply dies, too, then, I'll need to know that.
Thanks.
 
B

Bertram Scharpf

Hi,

Am Montag, 10. Aug 2009, 20:55:55 +0900 schrieb Peter Bailey:
Hmmm. Simple as that, eh? I though there was some internal thing, but,
thank you very much.
-Peter

If you do not want to reload the Ruby interpreter, you may fork
with sometihing like

fork do load "myscript.rb" end

What you initially wanted to do is continue inspite errors
occured. This could be done better using rescue blocks.

begin
load "myscript.rb"
rescue MyScriptError
...
end

Bertram
 
M

Matt Neuburg

Peter Bailey said:
Hi,
Can someone please tell me how you can can call out another Ruby script?
I have a lot of image processing scripts. Sometimes, rarely, they'll
simply fail because some of the images might be bad. But, I need to know
whether or not the images got processed or not. So, because an image
failure can literally lead to the whole Ruby script just failing, I'd
like to create a separate script that simply lists all of the files in
the input directory (separately from the processing script) and checks
to see if they all got processed or not. In DOS, I would use a "call"
statement. What's the equivalent in Ruby?
Thanks,
Peter

Just load the other script in the usual way and call something in it.
Example:

script1.rb:

def doStuff(x)
end

script2.rb:

require 'script1'
list_of_files = # whatever
list_of_files.each do |a_file|
begin
doStuff(a_file)
rescue
puts "#{a_file} didn't process correctly"
end
end

m.
???? m.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top