Asp.net core 无法从Dotnet核心ASP.NET解决方案执行linux命令
每当我尝试执行shell命令时,都会出现一个错误Asp.net core 无法从Dotnet核心ASP.NET解决方案执行linux命令,asp.net-core,Asp.net Core,每当我尝试执行shell命令时,都会出现一个错误 /bin/hostname: /bin/hostname: cannot execute binary file fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[0] An unhandled exception has occurred: Index was outside the bounds of the array. 我现在有 public
/bin/hostname: /bin/hostname: cannot execute binary file
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[0]
An unhandled exception has occurred: Index was outside the bounds of the array.
我现在有
public MachineData FindHostname()
{
Thread.Sleep(3000);
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "/bin/bash";
psi.Arguments = "/bin/hostname && /bin/uname";
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
Process proc = new Process
{
StartInfo = psi
};
proc.Start();
...
}
有人知道解决方法吗?如果从命令行尝试,您会发现它不起作用,与ASP.NET无关。您需要为bash提供
-c
标志才能运行commandsAbove。谢谢,我会试试。你也可以使用UseShellExecute=true
设置。它完全可以用于这种情况;希望通过shell运行命令…:)我很抱歉,但它将如何工作。我不明白。任何详细的回答。在我的例子中,我提供了-c,但它仍然给出了一个错误。你犯了什么错误?