os.userInfo([options])
-
options
<Object>-
encoding
<string> 用于解释结果字符串的字符编码。如果encoding
设置为'buffer'
,则username
、shell
和homedir
的值将是Buffer
实例。默认值:'utf8'
。¥
encoding
<string> Character encoding used to interpret resulting strings. Ifencoding
is set to'buffer'
, theusername
,shell
, andhomedir
values will beBuffer
instances. Default:'utf8'
.
-
-
返回:<Object>
¥Returns: <Object>
返回有关当前有效用户的信息。在 POSIX 平台上,这通常是密码文件的子集。返回的对象包括 username
、uid
、gid
、shell
和 homedir
。在 Windows 上,uid
和 gid
字段是 -1
,而 shell
是 null
。
¥Returns information about the currently effective user. On POSIX platforms,
this is typically a subset of the password file. The returned object includes
the username
, uid
, gid
, shell
, and homedir
. On Windows, the uid
and
gid
fields are -1
, and shell
is null
.
os.userInfo()
返回的 homedir
的值由操作系统提供。这与 os.homedir()
的结果不同,后者在回退到操作系统响应之前查询主目录的环境变量。
¥The value of homedir
returned by os.userInfo()
is provided by the operating
system. This differs from the result of os.homedir()
, which queries
environment variables for the home directory before falling back to the
operating system response.
如果用户没有 username
或 homedir
,则抛出 SystemError
。
¥Throws a SystemError
if a user has no username
or homedir
.