开发者

How can I get the username of the person who initialised the file in ruby?

How can I get the username of the person who initialised the file in ruby?

I'm using w开发者_如何学编程indows xp. and ruby 1.9.2


Try this:

require 'etc'
File.stat("myfile").uid     ->      666 for example
puts 'my file owned by', Etc.getpwuid(uid).name


You can try %x{ECHO USERNAME}.chomp (I can't verify that this will work, as I cannot recall the variable in windows that is the username)


This worked for me in the end.

require 'win32ole'
network=WIN32OLE.new("Wscript.Network")
user = network.username
puts user

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜