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

后端 未结 8 1265
醉梦人生
醉梦人生 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条回答
  •  旧时难觅i
    2020-12-29 21:07

    As an addendum, I've been surprised a few times when I've used backticks and saw output "slipping past" my variables when running scripts from the command line.

    Invariably, the issue is that the text I'm seeing is actually coming from stderr rather than stdout. So, to wrangle that text into stdout as well, remember to append 2>&1 to the command you're trying to run.

    I hope that's helpful to someone. I just wasted twenty minutes re-learning this lesson :)

提交回复
热议问题