【问题标题】:.Net Core Process.Start on Linux.Net Core Process.在 Linux 上启动
【发布时间】:2017-12-13 09:11:18
【问题描述】:

在 Linux 上运行我的 .Net Core 应用程序时遇到以下问题。

这是一个例外:

System.ComponentModel.Win32Exception (0x80004005): Permission denied
   at Interop.Sys.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Int32& lpChildPid, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at Ombi.Schedule.Jobs.Ombi.OmbiAutomaticUpdater.<Update>d__18.MoveNext() in C:\projects\requestplex\src\Ombi.Schedule\Jobs\Ombi\OmbiAutomaticUpdater.cs:line 218

代码如下:

var updaterFile = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
     "TempUpdate", $"Ombi.Updater");

var start = new ProcessStartInfo
{
    UseShellExecute = false,
    CreateNoWindow = true,
    FileName = updaterFile,
    Arguments = GetArgs(settings), // This just gets some command line arguments for the app i am attempting to launch
    WorkingDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "TempUpdate"),
};

using (var proc = new Process { StartInfo = start })
{
    proc.Start();
}

好像是在调用.Start()的时候抛出了异常。

我不知道为什么会这样,文件和文件夹的权限已设置为 777。

【问题讨论】:

  • 这是一个独立的部署
  • 如果有人需要帮助,这篇文章的最后一个答案帮助了我stackoverflow.com/questions/45132081/…
  • 您的 .NET 代码看起来不错。我将首先使用一些已知的内置工具(例如“/bin/ping google.com”)测试您的代码,以确认该问题与 ACL 相关。此外,检查 Ombi 树中较高的所有父目录。更新程序具有执行权限。您可以在 Unix & LinuxAsk Ubuntu StackExchange 站点中查找更多信息。
  • 也许上传一个压缩包?
  • 您是否检查过您的 SELinux 或您的发行版中的任何内容?关闭它只是为了测试,看看它是否会工作。

标签: .net linux .net-core


【解决方案1】:

多年后,我遇到了同样的错误,并且不喜欢为此制作 .dll 可执行文件的方法。而是将 FileName 设置为“dotnet”并将 dll 路径作为第一个参数传递就可以了。

var updaterFile = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
     "TempUpdate", $"Ombi.Updater");

var start = new ProcessStartInfo
{
    UseShellExecute = false,
    CreateNoWindow = true,
    FileName = "dotnet", // dotnet as executable
    Arguments = updaterFile + " " +GetArgs(settings),  // first argument as dll filepath
    WorkingDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "TempUpdate"),
};

using (var proc = new Process { StartInfo = start })
{
    proc.Start();
}

【讨论】:

  • 我想这只有在他们的机器上安装了 dotnet 才能工作,如果它是一个独立的应用程序,那么这将不起作用
  • 那是我的愚蠢。你是绝对正确的。 @JamieRees
【解决方案2】:

一个很好的诊断工具是查看您是否可以直接从 shell 执行文件(如果您在 Windows 上,则在 WSL 中)。

从 Windows 的角度来看,您很容易忘记您需要将可执行文件标记为 linux 上的可执行文件。如果您不能自己执行,chmod 775 /your/file 可能会有所帮助。

【讨论】:

  • chmod 命令之后,我可以手动执行文件,但仍然不能通过Process.Start。我尝试使用strace 进行调查,虽然没有帮助,但最终放弃了。您可以在此处查看 strace 输出:github.com/JeroenBos/JBSnorro.LayoutEngine/issues/17
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-04
  • 2018-09-14
  • 2016-06-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多