.Net Core Process.Start on Linux

Jam*_*ees 10 .net linux .net-core

在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
Run Code Online (Sandbox Code Playgroud)

这是代码:

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();
}
Run Code Online (Sandbox Code Playgroud)

看来我们打电话时会抛出异常.Start().

我不确定为什么会发生这种情况,文件和文件夹的权限已设置为777.

小智 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();
}
Run Code Online (Sandbox Code Playgroud)

  • 我想这只有在机器上安装了 dotnet 时才有效,如果它是一个独立的应用程序,那么这将不起作用 (2认同)