0

I'm trying to run some tests in Ruby that requires running external Ruby files/programs.

In Windows console I use irb to run Ruby program that calls another Ruby program located in this same directory like this:

irb(main):018:0> puts system "ruby1.8 tmp.rb"
false
=> nil

However it always return false.

How can I solve this problem.

I have several versions of Ruby installed on Windows and I need to run a specific version of Ruby chosen on the command line.

I have already tried to rename executable ruby.exe to ruby1.8.exe and it works properly from the command line but not with the 'system' command.

Multiple classes of the same name in Ruby

asked Feb 25, 2014 at 13:49
4
  • have you tried puts system "ruby tmp.rb" ? Commented Feb 25, 2014 at 13:52
  • 1
    show the content of tmp.rb file Commented Feb 25, 2014 at 13:52
  • 1
    For me, that is the wrong approach. Normally you would do the following: require or load the external Ruby program; call the method that is called by calling it external (no argument). This will work all the time. Commented Feb 25, 2014 at 13:57
  • What happens if you run ruby1.8 tmp.rb directly from the Windows console? Commented Feb 25, 2014 at 14:22

1 Answer 1

2

From the docs:

system returns true if the command gives zero exit status, false for non zero exit status.

Use backticks instead of system to capture the output:

output = `ruby tmp.rb`
p output
answered Feb 25, 2014 at 14:20

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.