How to run linux command in rake file

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.

On Nov 20, 8:06 am, Vamsi K. [email protected]
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: RDoc Documentation

Jeff
p.s. Please don’t say “reply ASAP” when posting. Everyone here is
donating their free time and energy already. :slight_smile:

purpleworkshops.com

How can I unsubscribe this?

Judy> Date: Fri, 21 Nov 2008 10:45:33 +0100> From:
[email protected]> To: [email protected]>
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%2Fadsfac.net%2Flink.asp%3Fcc%3DHOT056.76008.0%26clk%3D1%26creativeID%3D108913&_t=773821977&_r=HoT_tagline&_m=EXT

On Nov 20, 2:55 pm, Jeff [email protected] wrote:

p.s. Please don’t say “reply ASAP” when posting. Everyone here is
donating their free time and energy already. :slight_smile:

Fred Cheung wrote a little article on his blog about that;

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

This is urgent

Plz reply ASAP"

On Thu, Nov 20, 2008 at 3:06 PM, Vamsi K.
[email protected] 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 L. [email protected]

Vamsi K. 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

Gabriel L. wrote:

On Thu, Nov 20, 2008 at 3:06 PM, Vamsi K.
[email protected] 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 L. [email protected]

Thanks all of you for the reply.
–vamsi krishna.