How to call shell commands from Ruby

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

    The backticks (`) method is the easiest one to call shell commands from Ruby. It returns the result of the shell command:

         url_request = 'http://google.com'
         result_of_shell_command = `curl #{url_request}`
    

提交回复
热议问题