[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

detect user

Ryan Kaye

8/20/2006 6:41:00 PM

Hi

Im new to ruby and trying to learn by building a small app for mac osx.
So far I love it. However, one thing I want to do is to detect the
current user (of the app's) system directory name ie -
/Users/johnsmith/... - johnsmith being what I want get.

One way I tried was to use a system call such as

system("Users")

but although this will output the current user in the console it will
not store the name as a variable because, as im sure you know, the
system call returns a boolean and not the result of the call.

Anybody know of an alternative way.

Cheers

R

--
Posted via http://www.ruby-....

4 Answers

Ryan Kaye

8/20/2006 6:53:00 PM

0

Joey wrote:
> You can use ``, like:
> users = `Users`.chomp OR
> user = `whoami`.chomp
>
> j`ey
> http://www.eachmap...

Magic - so simple

Cheers

--
Posted via http://www.ruby-....

Morton Goldberg

8/20/2006 7:25:00 PM

0

I'm running on OS X, too. Here is what works for me in getting user
environment info:

user = ENV['USER'] # user login name
home = ENV['HOME'] # user login path

The second seems to be what you are looking for.

Regards, Morton

On Aug 20, 2006, at 2:41 PM, Ryan Kaye wrote:

> Im new to ruby and trying to learn by building a small app for mac
> osx.
> So far I love it. However, one thing I want to do is to detect the
> current user (of the app's) system directory name ie -
> /Users/johnsmith/... - johnsmith being what I want get.
>
> One way I tried was to use a system call such as
>
> system("Users")
>
> but although this will output the current user in the console it will
> not store the name as a variable because, as im sure you know, the
> system call returns a boolean and not the result of the call.
>
> Anybody know of an alternative way.

Ryan Kaye

8/20/2006 7:39:00 PM

0

Morton Goldberg wrote:
> I'm running on OS X, too. Here is what works for me in getting user
> environment info:
>
> user = ENV['USER'] # user login name
> home = ENV['HOME'] # user login path
>
> The second seems to be what you are looking for.
>
> Regards, Morton

Nice one

Thanks

--
Posted via http://www.ruby-....

Gennady Bystritsky

8/21/2006 4:12:00 PM

0

require 'etc'

current_user = Etc.getpwuid

p current_user.name
p current_user.dir

It works on any Unix system, not only on Mac OS X. Not sure about
Windows, though.

Enjoy ;-)
Gennady.

> -----Original Message-----
> From: Morton Goldberg [mailto:m_goldberg@ameritech.net]
> Sent: Sunday, August 20, 2006 12:25 PM
> To: ruby-talk ML
> Subject: Re: detect user
>
> I'm running on OS X, too. Here is what works for me in getting user
> environment info:
>
> user = ENV['USER'] # user login name
> home = ENV['HOME'] # user login path
>
> The second seems to be what you are looking for.
>
> Regards, Morton
>
> On Aug 20, 2006, at 2:41 PM, Ryan Kaye wrote:
>
> > Im new to ruby and trying to learn by building a small app for mac
> > osx.
> > So far I love it. However, one thing I want to do is to detect the
> > current user (of the app's) system directory name ie -
> > /Users/johnsmith/... - johnsmith being what I want get.
> >
> > One way I tried was to use a system call such as
> >
> > system("Users")
> >
> > but although this will output the current user in the
> console it will
> > not store the name as a variable because, as im sure you know, the
> > system call returns a boolean and not the result of the call.
> >
> > Anybody know of an alternative way.
>
>