小编Itn*_*niv的帖子

使用 dotnet core 在 Centos 上执行 linux 命令

我正在 CentOS 机器上运行一个 .NET Core 控制台应用程序。下面的代码正在为普通命令执行,如uptime,但不执行lz4 -dc --no-sparse vnp.tar.lz4 | tar xf - Logs.pdf

try
{
    var connectionInfo = new ConnectionInfo("server", "username", new PasswordAuthenticationMethod("username", "pwd"));
    using (var client = new SshClient(connectionInfo))
    {
        client.Connect();

        Console.WriteLine("Hello World!");
        var command = client.CreateCommand("lz4 -dc --no-sparse vnp.tar | tar xf - Logs.pdf");
        var result = command.Execute();
        Console.WriteLine("yup ! UNIX Commands Executed from C#.net Application");
        Console.WriteLine("Response came form UNIX Shell" + result);

        client.Disconnect();
    }
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}
Run Code Online (Sandbox Code Playgroud)

预期的输出是需要提取并保存在当前位置的 …

centos tar lz4 .net-core

4
推荐指数
1
解决办法
7027
查看次数

标签 统计

.net-core ×1

centos ×1

lz4 ×1

tar ×1