首页 > 解决方案 > 有什么方法可以让 System.Diagnostics.Process 尊重 Linux 用户的次要组?

问题描述

帮助!

在Linux上运行 .NET CORE 。

我在打开基于 Linux 中的辅助组具有读取访问权限的文件时遇到问题。为了测试这一点,我只需为当前用户执行 Linux 命令“id”:

var proc = new System.Diagnostics.Process();
proc.StartInfo.UserName = "JohnNonRootUser";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = "id";
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();

while (!proc.StandardOutput.EndOfStream)
{
    sb.AppendLine(proc.StandardOutput.ReadLine());
}
var resID = sb.ToString();

结果是:

uid=1002(JohnNonRootUser) gid=1002(JohnNonRootUser) groups=1002(JohnNonRootUser)

但如果我从命令行手动执行,它是正确的:

JohnNonRootUser@mybox:/$ id
uid=1002(JohnNonRootUser) gid=1002(JohnNonRootUser) groups=1002(JohnNonRootUser),1003(SomeOtherGroup)

谁能让我知道如何解决这个问题?

标签: linux.net-coreprocesssystem.diagnostics

解决方案


推荐阅读