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.
Sardaukary (Guest)
on 2005-11-27 20: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?
billk (Guest)
on 2005-11-27 21:10
(Received via mailing list)
Hi,

From: <removed_email_address@domain.invalid>
>
>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.