Ruby Tip: Fetch a terminal command output using bartick directive

If you need to extract text from a command output within Ruby, the bartick directive could come in handy.

Syntax is: `command`

One of the useful examples is to retrieve a path of a command:

gcc_path = `which gcc`

There are more applications, I guess I should leave it to you to discover.

Advertisements

About Jones Lee

Nothing much about me..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: