Suppressing the output of a command run using 'system' method while running it in a ruby script

后端 未结 8 1264
醉梦人生
醉梦人生 2020-12-29 20:13

I am not sure if this makes sense but I am thinking if there is a way to suppress the output shown for a command when run using the system method in ruby? I mea

8条回答
  •  自闭症患者
    2020-12-29 20:49

    IO.popen

    This is another good option:

    IO.popen(['echo', 'a']) do |f|
      f.read == "a\n" or raise
    end
    $?.exitstatus == 0 or raise
    

    Nothing will get output to your stdout.

    http://www.ruby-doc.org/core-2.1.4/IO.html#method-c-popen

提交回复
热议问题