gpt4 book ai didi

ruby - 为什么我在 Ruby 中的反引号不起作用?

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

我有这个代码

`ifconfig`

%x(ifconfig)

system("ifconfig")

当我运行它时,只有“system("ifconfig")”起作用。我知道是因为我先分别运行它们。

最佳答案

反引号和 %x 变体在变量中返回结果的输出。 system() 将调用命令并返回 !!return_code

1.9.3p327 :001 > `ifconfig`
=> "eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>..."

1.9.3p327 :002 > %x(ifconfig)
=> "eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>..."

1.9.3p327 :003 > system("ifconfig")
eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
...
=> true

关于ruby - 为什么我在 Ruby 中的反引号不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14093146/

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