How to call shell commands from Ruby

前端 未结 20 2358
旧时难觅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 02:02

    I'm definitely not a Ruby expert, but I'll give it a shot:

    $ irb 
    system "echo Hi"
    Hi
    => true
    

    You should also be able to do things like:

    cmd = 'ls'
    system(cmd)
    

提交回复
热议问题