开发者

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

开发者 https://www.devze.com 2023-03-22 04:08 出处:网络
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.2Try this:

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

精彩评论

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

关注公众号