In trying to learn about Ruby execution methods, I found this blog post on five ways to run commands in Ruby http://mentalized.net/journal/2010/03/08/5_ways_to_run_commands_from_ruby/
The author creates a file err.rb, which outputs two lines, one on STDOUT, the other on STDERR
#!/usr/bin/env ruby
puts "out"
STDERR.puts "error"
The first way he tries to run it is with Kernal#` (backticks)
>> `./err.rb`
err
=> "out\n"
The point this illustrates is that when run with backticks
STDERR is output, but not captured STDOUT is captured
When I tried to duplicate this on my system, I got a permission error
localhost:sites mike$ `./err.rb`
-bash: ./err.rb: Permission denied
I tried sudo ./err.rb with no change.
I can run ruby err.rb but that produces a different result than what the author got. Namely by running ruby err.rb I get
out
error
Can someone explain why I’m getting a permission error trying to run it with backticks, and also generally what the whole purpose of running it with backticks is.
Try add permission to execute, use “chmod +x that_file_name”
to execute using format “./file” the ‘file’ need to have execute permission
It runs when you ruby because ruby has execute permission and it simply read that file.
Try this