How to call shell commands from Ruby

前端 未结 20 2067
旧时难觅i
旧时难觅i 2020-11-22 01:10

How do I call shell commands from inside of a Ruby program? How do I then get output from these commands back into Ruby?

20条回答
  •  别那么骄傲
    2020-11-22 01:45

    Here's the best article in my opinion about running shell scripts in Ruby: "6 Ways to Run Shell Commands in Ruby".

    If you only need to get the output use backticks.

    I needed more advanced stuff like STDOUT and STDERR so I used the Open4 gem. You have all the methods explained there.

提交回复
热议问题