Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 无法从Dotnet核心ASP.NET解决方案执行linux命令_Asp.net Core - Fatal编程技术网

Asp.net core 无法从Dotnet核心ASP.NET解决方案执行linux命令

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

每当我尝试执行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 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,但它仍然给出了一个错误。你犯了什么错误?