<分区>
我正在尝试执行以下操作..
if "ps | grep -e file" then
true;
else
false;
我需要做什么才能使 if 语句中的字符串执行列出的 linux 命令?
<分区>
我正在尝试执行以下操作..
if "ps | grep -e file" then
true;
else
false;
我需要做什么才能使 if 语句中的字符串执行列出的 linux 命令?
最佳答案
只需使用 system("command")
。如果命令成功执行,它将返回 true。
编辑 再读一遍你的问题,我相信你要找的是这个:
if `ps | grep -e file`.empty? # no matches
true
else
false
end
关于ruby - 在 ruby 中运行 linux 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4944526/