Calling another Ruby script

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

Peter B. wrote:

Thanks,
Peter

system(“ruby myscript.rb”)

Tim H. wrote:

Peter B. wrote:

Thanks,
Peter

system(“ruby myscript.rb”)

Hmmm. Simple as that, eh? I though there was some internal thing, but,
thank you very much.
-Peter

2009/8/10 Peter B. [email protected]:

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

Hi,

Am Montag, 10. Aug 2009, 20:55:55 +0900 schrieb Peter B.:

Tim H. wrote:

Peter B. wrote:

Thanks,
Peter

system(“ruby myscript.rb”)

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

Robert K. wrote:

2009/8/10 Peter B. [email protected]:

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

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.

2009/8/10 Peter B. [email protected]:

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?

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.

What about preventing that? I mean, you could make sure that it does
not stop processing even if the external program failed. You can even
catch an exit as a quick hack:

$ ruby19 -e ‘begin; exit(12); rescue SystemExit => e; printf “tried
exit(%i)\n”, e.status; end’
tried exit(12)
$ echo $?
0
$

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.

But if the first script dies, there is no chance to invoke the second
script from it. Or do you want to start the second script and have
that call the first script? In any way I still do not see the need
for two scripts unless your Ruby interpreter could actually crash.

Kind regards

robert

Peter B. [email protected] wrote:

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.

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