PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Assigne command ouput to a variable
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Assigne command ouput to a variable

Réponse
 
LinkBack Outils de la discussion
Vieux 07/11/2007, 08h58   #1
Dragoescu Daniel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Assigne command ouput to a variable

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

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 me? Thanks in advance.



  Réponse avec citation
Vieux 07/11/2007, 09h14   #2
Stefano Crocco
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Assigne command ouput to a variable

Alle mercoled=EC 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 =3D system("du -s /mnt/hdd/ | cut -f1") puts var1 or
>
> var1 =3D 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 me? Thanks in advance.


You can use backticks instead of system:

  Réponse avec citation
Vieux 07/11/2007, 09h17   #3
Stefano Crocco
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Assigne command ouput to a variable

Alle mercoled=EC 7 novembre 2007, Stefano Crocco ha scritto:
> Alle mercoled=EC 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 =3D system("du -s /mnt/hdd/ | cut -f1") puts var1 or
> >
> > var1 =3D 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 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 =3D `"du -s /mnt/hdd/ | cut -f1"`
puts var1

I hope this s

Stefano

  Réponse avec citation
Vieux 07/11/2007, 09h35   #4
Dragoescu Daniel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Assigne command ouput to a variable

Hello!

It seems to work with:
----
var1 =3D `du -s /mnt/hdd/ | cut -f1`
puts var1
----
Thank you for the answare!

-----Original Message-----
From: Stefano Crocco [mailto:stefano.crocco@alice.it]=20
Sent: Wednesday, November 07, 2007 11:17 AM
To: ruby-talk ML
Subject: Re: Assigne command ouput to a variable

Alle mercoled=EC 7 novembre 2007, Stefano Crocco ha scritto:
> Alle mercoled=EC 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=20
> > and i want that the ouput of that command to be assigne to a=20
> > variable, something like this:
> >
> > var1 =3D system("du -s /mnt/hdd/ | cut -f1") puts var1 or
> >
> > var1 =3D 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 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 =3D `"du -s /mnt/hdd/ | cut -f1"`
puts var1

I hope this s

Stefano



  Réponse avec citation
Vieux 07/11/2007, 09h51   #5
elof@elof.dk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Assigne command ouput to a variable


Hi

You can get both the output from the command and its return value:

var1 = `du -s /mnt/hdd/ | cut -f1`
puts $?.exitstatus
puts var1

Kristian


On Wed, 7 Nov 2007 18:35:55 +0900, "Dragoescu Daniel"
<daniel.dragoescu@axigen.com> wrote:
> Hello!
>
> It seems to work with:
> ----
> var1 = `du -s /mnt/hdd/ | cut -f1`
> puts var1
> ----
> Thank you for the answare!
>
> -----Original Message-----
> From: Stefano Crocco [mailto:stefano.crocco@alice.it]
> Sent: Wednesday, November 07, 2007 11:17 AM
> To: ruby-talk ML
> 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 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 s
>
> Stefano



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h51.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16045 seconds with 13 queries