gpt4 book ai didi

ruby - 使用 rake sh 时如何检索命令的输出?

转载 作者:数据小太阳 更新时间:2023-10-29 06:33:24 26 4
gpt4 key购买 nike

我正在使用 sh 运行命令,需要读取该命令的输出。例如

sh "whoami"

但是 sh 似乎只返回 true 而不是包含 whoami 命令输出的字符串。有谁知道解决方案吗?

最佳答案

有几种方式:

output = `whoami`

#or

output = %x[whoami]

# or using 'system' but in case of errors it's gonna return false

output = system "whoami"

关于ruby - 使用 rake sh 时如何检索命令的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1441894/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com