2015-05-12 61 views
0

我试图获得在Ruby中从一个系统调用的值的值:获取系统调用

distro = system('lsb_release -is') 
distver = system('lsb_release -rs | cut -c1-2') 

我想从lsb_release返回进入的变量。但如果我做了puts distroputs distver我只是变成了现实。

有什么办法从他们那里获得价值吗?

+0

它已经被问过很多次了。这里有一个答案:http://stackoverflow.com/questions/690151/getting-output-of-system-calls-in-ruby –

回答

1

你可以去用

d = `date` 
e = IO.popen("date").read 

花一些时间也与IO.popenIO.popen2IO.popen3