How do I find the name of the current user?

I'm thinking Etc.getlogin followed by Etc.getpwnam.gecos might be best
on unix, is there a windowsy equivalent?

Thanks,
Sam

Would this help you?

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/135205

Csaba

···

On 2005-04-03, Sam Roberts <sroberts@uniserve.com> wrote:

I'm thinking Etc.getlogin followed by Etc.getpwnam.gecos might be best
on unix, is there a windowsy equivalent?

On Win XP and 2000 I think you can depend on ENV['USERNAME'], on older
windows versions I'm not sure...

- alan

Quoting csaba@phony_for_avoiding_spam.org, on Sun, Apr 03, 2005 at 11:54:43AM +0900:

···

On 2005-04-03, Sam Roberts <sroberts@uniserve.com> wrote:
> I'm thinking Etc.getlogin followed by Etc.getpwnam.gecos might be best
> on unix, is there a windowsy equivalent?

Would this help you?
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/135205

It looks great, but I don't want to use it until its in the stdlib. Its
a little more than I want to get the name of the current user.

But, I'll remember, I might need it in the future.

Thanks
Sam

A quick and dirty solution that mostly works: ENV['LOGNAME'] (on Unix) or ENV['USERNAME'] (on Windows)

···

--
Best regards,

Alexey Verkhovsky

Ruby Forum: http://ruby-forum.org (moderator)
RForum: http://rforum.andreas-s.net (co-author)
Instiki: http://instiki.org (maintainer)

Sam Roberts wrote:

Quoting csaba@phony_for_avoiding_spam.org, on Sun, Apr 03, 2005 at

11:54:43AM +0900:

> > I'm thinking Etc.getlogin followed by Etc.getpwnam.gecos might be

best

> > on unix, is there a windowsy equivalent?
>
> Would this help you?
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/135205

It looks great, but I don't want to use it until its in the stdlib.

Its

a little more than I want to get the name of the current user.

But, I'll remember, I might need it in the future.

I don't know how portable this is, but:

irb(main):001:0> ENV["USER"]
=> "cmills"

-Charlie

···

> On 2005-04-03, Sam Roberts <sroberts@uniserve.com> wrote: