Forum: Ruby backtick with variables?

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.
86f3bf0c7542ede72e343bf658731221?d=identicon&s=25 Sardaukary (Guest)
on 2005-11-27 19:58
(Received via mailing list)
I want to run an external command and capture the output.

hosts =`net view`

will store the results from running net view (XP command to list
machines on network) in a string called hosts.

How do I execute a command stored in a string and capture its output
though?
4feed660d3728526797edeb4f0467384?d=identicon&s=25 billk (Guest)
on 2005-11-27 20:10
(Received via mailing list)
Hi,

From: <Sardaukary@gmail.com>
>
>I want to run an external command and capture the output.
>
> hosts =`net view`
>
> will store the results from running net view (XP command to list
> machines on network) in a string called hosts.
>
> How do I execute a command stored in a string and capture its output
> though?

cmd = "net view"
hosts = `#{cmd}`

There's also popen() if you would prefer to read the output from a
pipe.


Regards,

Bill
This topic is locked and can not be replied to.