Catching command-line errors using %x

后端 未结 4 1156
走了就别回头了
走了就别回头了 2021-01-11 13:16

Whenever you want to execute something on the command line, you can use the following syntax:

%x(command to run)

However, I want to catch a

4条回答
  •  借酒劲吻你
    2021-01-11 13:45

    You might want to redirect stderr to stdout:

    result = %x(command to run 2>&1)
    

    Or if you want to separate the error messages from the actual output, you can use popen3:

    require 'open3'
    stdin, stdout, stderr = Open3.popen3("find /proc")
    

    Then you can read the actual output from stdout and error messages from stderr.

提交回复
热议问题