Meeshoo Meeshoo - 2 years ago 80
Ruby Question

How to call an external script with arguments?

I have a Ruby script that should call various scripts when the execution throws an error. How can I call a script with two arguments?

For the moment I am using the code below but I need to also send two arguments to

my_script = ""
%x( #{my_script})

Answer Source

You almost figured it out, just add the params:

my_script = ""
%x( #{my_script} #{arg1} #{arg2})

You may also want to check the return code:

if $? == 0
   puts "script executed successfully"
   puts "script returned an error, exit code: #{$?.to_s.split('exit ')[-1]}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download