Getting another Ruby script to run inside a Ruby script

Hello,
I’m getting failures when I try to run these two Ruby scripts inside
this one here. But, in the command shell, when I go to that directory, I
can run those other two Ruby scripts just fine. All I’m doing here is
parsing out particular filetypes, by virtue of the filenames and
extensions, and then trying to run separate Ruby scripts on those files.

require ‘yaml’
require ‘fileutils’
Dir.chdir(“F:/workflows/grafix/images-BNA”)
config =
YAML.load_file(“F:/workflows/grafix/images-BNA/SMMS-images.yaml”)
data1 = config[“filenames”]
data2 = config[“destinations”]
data1.keys.each do |filetype|
filenames = data1[filetype]
target = data2[filetype]
filenames.split(", ").each do |pattern|
if pattern == “aicpa*.gif”
puts pattern
begin
puts “executing the AICPA GIF script.”
E:/Apps/scripts/ruby/FileTrain/SMMS2/AICPA/AICPA_gif.rb
rescue
puts “That Ruby script, AICPA_gif.rb, did not run.”
end
end
if pattern == “aicpa*.jpg”
puts pattern
begin
puts “executing the AICPA JPEG script.”
E:/Apps/scripts/ruby/FileTrain/SMMS2/AICPA/AICPA_jpeg.rb
rescue
puts “That Ruby script, AICPA_jpeg.rb, did not run.”
end
end
end
end

This is my output:
aicpa*.gif
executing the AICPA GIF script.
That Ruby script, AICPA_gif.rb, did not run.
aicpa*.jpg
executing the AICPA JPEG script.
That Ruby script, AICPA_jpeg.rb, did not run.

Thank you,
Peter

Peter, you just made my eyes bleed.

E:/Apps/scripts/ruby/FileTrain/SMMS2/AICPA/AICPA_gif.rb

Are you trying to use backticks?

Why aren’t you using load or require?

What do your unit tests look like?

Scott S. wrote in post #1169784:

Peter, you just made my eyes bleed.

E:/Apps/scripts/ruby/FileTrain/SMMS2/AICPA/AICPA_gif.rb

Are you trying to use backticks?

Why aren’t you using load or require?

What do your unit tests look like?

Yes, I use backticks. I use them a lot because I have to do a lot of
command shell stuff.
I tried using system("…") here, but, that didn’t work. I got it to
work here, at least where it could tell me that the scripts did not run.
I’m sorry, but, I don’t know what you mean by “load” or “require.” Do I
have to “require” an outside script that I want to run inside this
script? I’ll look up what “load” mean.
Thanks.

Hi Peter,

load and require are for dealing with Ruby code. In your code example
your files end with .rb, so I assume they contain ruby code. That’s why
I recommend you explore load and require.

Backtics are for executing system commands.

C:\Users\Scott>irb
irb(main):001:0> system(“pwd”)
/c/Users/Scott
=> true
irb(main):002:0> pwd = pwd
=> “/c/Users/Scott\n”
irb(main):003:0> puts pwd
/c/Users/Scott
=> nil
irb(main):004:0> exit

The path to a ruby file is not a system command.

Depending on what you are trying to do you probably want to include a
call to the ruby interpreter passing it a file name to execute.

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