From: Stefano Crocco Date: 2007-11-07T18:17:11+09:00 Subject: Re: Assigne command ouput to a variable Alle mercoledì 7 novembre 2007, Stefano Crocco ha scritto: > Alle mercoledì 7 novembre 2007, Dragoescu Daniel ha scritto: > > Hello guys! > > > > I am a newbie in ruby and i have a question. I run a system command and i > > want that the ouput of that command to be assigne to a variable, > > something like this: > > > > var1 = system("du -s /mnt/hdd/ | cut -f1") puts var1 or > > > > var1 = exec("du -s /mnt/hdd/ | cut -f1") puts var1 > > > > but system return 0 or 1 if command is failed or succesful, and exec > > don't assigne the output to variable var1. > > > > Can you help me? Thanks in advance. > > You can use backticks instead of system: Sorry, I hit the send button by mistake. You can use backticks instead of system: var1 = `"du -s /mnt/hdd/ | cut -f1"` puts var1 I hope this helps Stefano