[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

how to read output of shell command to variable?

sin kanti

4/1/2005 10:53:00 PM

Hi,

In perl, we can do

$output = `file filename.txt`;

How can i do this in Ruby?
I know that there is system to run shell command like this;

system("file","filename.txt")

but how to return the output of "file" command to variable?


Sinchai


7 Answers

dblack

4/1/2005 10:57:00 PM

0

Andrew Walrond

4/1/2005 10:59:00 PM

0

On Friday 01 April 2005 23:52, sin kanti wrote:
> Hi,
>
> In perl, we can do
>
> $output = `file filename.txt`;
>
> How can i do this in Ruby?

$output = `file filename.txt`

;)


Robert Klemme

4/2/2005 7:23:00 AM

0


"Andrew Walrond" <andrew@walrond.org> schrieb im Newsbeitrag
news:200504012358.52121.andrew@walrond.org...
> On Friday 01 April 2005 23:52, sin kanti wrote:
>> Hi,
>>
>> In perl, we can do
>>
>> $output = `file filename.txt`;
>>
>> How can i do this in Ruby?
>
> $output = `file filename.txt`
>
> ;)

In fact, you can even add the ";" and keep the Perl code altogether. :-))

$output = `file filename.txt`;

Kind regards

robert

Josef 'Jupp' Schugt

4/3/2005 7:56:00 PM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robert Klemme wrote:
|
| "Andrew Walrond" <andrew@walrond.org> schrieb im Newsbeitrag
| news:200504012358.52121.andrew@walrond.org...
|
|> On Friday 01 April 2005 23:52, sin kanti wrote:
|>> In perl, we can do
|>>
|>> $output = `file filename.txt`;
|>>
|>> How can i do this in Ruby?
|>
|> $output = `file filename.txt`
|>
|> ;)
|
| In fact, you can even add the ";" and keep the Perl code altogether.
| :-))
|
| $output = `file filename.txt`;

I'd prefer Perl's qx:

$output = qx{file filename.txt}

In Ruby that is

output = x{file filename.txt}

Note the absence of the dollar sign at the beginning of the variable
name. The dollar has different meanings in Ruby and Perl.

Josef 'Jupp' Schugt
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail....

iD8DBQFCUBldrhv7B2zGV08RAh8/AJ4xXeLsNXniiR/8bFbVnzo5ZIDcyQCgp0wQ
Fv/VUex4eyIgthTEjvzdAf4=
=moeo
-----END PGP SIGNATURE-----



James Gray

4/3/2005 8:02:00 PM

0

On Apr 3, 2005, at 2:56 PM, Josef 'Jupp' Schugt wrote:

> I'd prefer Perl's qx:
>
> $output = qx{file filename.txt}
>
> In Ruby that is
>
> output = x{file filename.txt}

I'm pretty sure you meant:

output = %x{file filename.txt}

:)

James Edward Gray II



Blackheart

5/6/2011 1:41:00 AM

0

On May 3, 10:24 pm, Playa <johnpaulpont...@gmail.com> wrote:
> Hey,
>
> On May 2, 5:41 pm, Blackheart <blackheart666_2...@yahoo.com> wrote:
>
> > could you not quote the retards over Dakka
>
> Heh. I only miss 2-3 posters from Dakka.
> Kid was a hoot! I wonder if he's still there.
>
>    Playa

they made that goat fucker a moderator.

JohnPaulPontiff

5/6/2011 8:44:00 AM

0

Hey,

On May 5, 9:40 pm, Blackheart <blackheart666_2...@yahoo.com> wrote:
> a moderator

Ahahaaa! It takes all kinds ...


Playa