user1509208
user1509208

Reputation: 3

put exec output in a variable

I am new to ruby and trying to do some command line stuff.

Now I need to save the output of

exec 'cat /etc/system-release'

in a variable to scan it for a number.

Upvotes: 0

Views: 252

Answers (1)

Frederick Cheung
Frederick Cheung

Reputation: 84114

If you want to grab the output you're better off using system or backticks (or for longer running tasks, IO.popen)

In this case, it would be a lot faster to do

File.read('/etc/system-release')

rather than creating extra processes just to do this.

Upvotes: 2

Related Questions