Back tick equivalent

Just install ruby last Friday and tried to find the back tick equivalent as
in shell script or perl to get the program output w/o resort to some popen
trickery. Can not find it in the reference book or faq ?

e.g. what is the equivalent of below perl statement

@psout = `ps -elf | grep myusername`;

Jack Wei-Chi Cheng

Lexis-Nexis Corporation
Development Services Team
Framework group
9555 Springboro Pike
Miamisburg, OH45342
Location, B5F4S95

Backticks should work the same in ruby, if you want an array of lines,
you can do the following,

psout = ps -elf | grep myusername.split("\n")

without the .split("\n") you’d get one large string.

– alan

···

On Tue, Sep 17, 2002 at 04:04:24AM +0900, CHENG, WEI CHI (LNG) wrote:

Just install ruby last Friday and tried to find the back tick equivalent as
in shell script or perl to get the program output w/o resort to some popen
trickery. Can not find it in the reference book or faq ?

e.g. what is the equivalent of below perl statement

@psout = ps -elf | grep myusername;


Alan Chen
Digikata LLC

Hi,

What is your platform? At least on linux, I could do

puts `ps -elf | grep myusername`

In the pickaxe book, it is documented under Chapter “Built-in Classes and
Methods” in the Section “module Kernel” with method name “backquote”.

Regards,

Bill

···

===========================================================================
“CHENG, WEI CHI (LNG)” WEICHI.CHENG@lexisnexis.com wrote:

Just install ruby last Friday and tried to find the back tick equivalent as
in shell script or perl to get the program output w/o resort to some popen
trickery. Can not find it in the reference book or faq ?

e.g. what is the equivalent of below perl statement

@psout = ps -elf | grep myusername;

Or

psout = ps -elf.grep(/myusername/)

– Gotoken

···

At Tue, 17 Sep 2002 04:16:53 +0900, Alan Chen wrote:

psout = ps -elf | grep myusername.split("\n")

without the .split("\n") you’d get one large string.