Forum: Ruby on Rails how to run linux command in rake file

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
91a616ee807e220c8ffccb5f2ad33731?d=identicon&s=25 Vamsi Krishna (vamsikrishna)
on 2008-11-20 15:06
hi all,

 i need to grep a word count from a text file and i want to display the
count.
 i need all the above in a rake file , i tried it by using

   today_count= system("grep -R 'time' oct_10.txt | grep -R 'hi' | wc
-l")
   puts "today count is :#{today_count}"

  but today_count returns 'true' instead of count.


  plz reply ASAP.


Thanks..
--vamsi.
8217faf2bfdfa7daf10135d41ddd421e?d=identicon&s=25 Jeff Cohen (jeff)
on 2008-11-20 15:55
(Received via mailing list)
On Nov 20, 8:06 am, Vamsi Krishna <rails-mailing-l...@andreas-s.net>
wrote:
>   but today_count returns 'true' instead of count.
>
>   plz reply ASAP.
>
> Thanks..
> --vamsi.
> --
> Posted viahttp://www.ruby-forum.com/.

Try backticks instead:

output = `grep -R 'time' oct_10.txt | grep -R 'hi' | wc`

backticks will return whatever went to stdout.

For system(), rtfm: http://ruby-doc.org/core/

Jeff
p.s. Please don't say "reply ASAP" when posting. Everyone here is
donating their free time and energy already. :-)

purpleworkshops.com
Bc3e77f31c3b792a625439ac6fa4969d?d=identicon&s=25 Anil Rak (anil123)
on 2008-11-21 10:45
Vamsi Krishna wrote:
> hi all,
>
>  i need to grep a word count from a text file and i want to display the
> count.
>  i need all the above in a rake file , i tried it by using
>
>    today_count= system("grep -R 'time' oct_10.txt | grep -R 'hi' | wc
> -l")
>    puts "today count is :#{today_count}"
>
>   but today_count returns 'true' instead of count.
>
>
>   plz reply ASAP.
>
>
> Thanks..
> --vamsi.


Vamsi,
      I think here you using 'time' is a variable, instead of using that
variable try to append that var by using '<<'

--nan
99fd085ccefd3844a26ec564302c509a?d=identicon&s=25 Judy Khoo (Guest)
on 2008-11-21 11:51
(Received via mailing list)
How can I unsubscribe this?

Judy> Date: Fri, 21 Nov 2008 10:45:33 +0100> From:
rails-mailing-list@andreas-s.net> To: rubyonrails-talk@googlegroups.com>
Subject: [Rails] Re: how to run linux command in rake file> > > Vamsi
Krishna wrote:> > hi all,> > > > i need to grep a word count from a text
file and i want to display the> > count.> > i need all the above in a
rake file , i tried it by using> > > > today_count= system("grep -R
'time' oct_10.txt | grep -R 'hi' | wc> > -l")> > puts "today count is
:#{today_count}"> > > > but today_count returns 'true' instead of
count.> > > > > > plz reply ASAP.> > > > > > Thanks..> > --vamsi.> > >
Vamsi,> I think here you using 'time' is a variable, instead of using
that > variable try to append that var by using '<<'> > --nan> > > -- >
Posted via http://www.ruby-forum.com/.> >
_________________________________________________________________
AirNZ vs Pacific Blue & heaps more! Book now.
http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fad...
E60b2dc57668b5662ce3f07781e41710?d=identicon&s=25 Matthew Rudy Jacobs (matthewrudy)
on 2008-11-21 15:27
(Received via mailing list)
On Nov 20, 2:55 pm, Jeff <cohen.j...@gmail.com> wrote:
> p.s. Please don't say "reply ASAP" when posting. Everyone here is
> donating their free time and energy already. :-)

Fred Cheung wrote a little article on his blog about that;
http://spacevatican.org/2008/11/20/asap

"Things most likely to make me not reply to a message on a mailing
list:

    This is urgent

    Plz reply ASAP"
F4ae71a145a8960a4c29692c96e69dee?d=identicon&s=25 Gabriel Laskar (Guest)
on 2008-11-22 00:41
(Received via mailing list)
On Thu, Nov 20, 2008 at 3:06 PM, Vamsi Krishna
<rails-mailing-list@andreas-s.net> wrote:
>
>  but today_count returns 'true' instead of count.
normal, system() return true or false only, not stdout...

you can use ``, popen, or code that in ruby.

today_count = File.open('oct_10.txt').grep('time').grep('hi').size

(not tested)
--
Gabriel Laskar <bibi.skuk@gmail.com>
91a616ee807e220c8ffccb5f2ad33731?d=identicon&s=25 Vamsi Krishna (vamsikrishna)
on 2008-11-22 07:38
Gabriel Laskar wrote:
> On Thu, Nov 20, 2008 at 3:06 PM, Vamsi Krishna
> <rails-mailing-list@andreas-s.net> wrote:
>>
>>  but today_count returns 'true' instead of count.
> normal, system() return true or false only, not stdout...
>
> you can use ``, popen, or code that in ruby.
>
> today_count = File.open('oct_10.txt').grep('time').grep('hi').size
>
> (not tested)
> --
> Gabriel Laskar <bibi.skuk@gmail.com>


Thanks all of you for the reply.
--vamsi krishna.
This topic is locked and can not be replied to.