Execute linux command on Centos using dotnet core

前端 未结 1 1726
醉酒成梦
醉酒成梦 2020-12-19 18:57

I\'m running a .NET Core Console Application on CentOS box. The below code is executing for normal command like uptime, but not executing for lz4 -dc --no

相关标签:
1条回答
  • 2020-12-19 19:16

    If application is running on Linux machine then you can try this also:

    string command = "write your command here";
    string result = "";
    using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
    {
        proc.StartInfo.FileName = "/bin/bash";
        proc.StartInfo.Arguments = "-c \" " + command + " \"";
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.RedirectStandardOutput = true;
        proc.StartInfo.RedirectStandardError = true;
        proc.Start();
    
        result += proc.StandardOutput.ReadToEnd();
        result += proc.StandardError.ReadToEnd();
    
        proc.WaitForExit();
    }
    return result;
    
    0 讨论(0)
提交回复
热议问题