2017-09-26 5 views
0

CentOSのボックスでdotnetコアコンソールアプリケーションを実行しています。以下のコードは、通常のコマンドと同様の "稼働時間"に対して実行されています。しかしために実行していない「LZ4 -dc --no-スパースvnp.tar.lz4 |タールXF - Logs.pdf」CentOS上でlinuxコマンドをdotnetコアで実行する

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); 
     } 

の予想される出力はLogs.pdfファイルが抽出され、現在の場所に保存する必要があります。アプリケーションは、Linuxマシン上で実行されている場合イムは

答えて

0

その後、あなたもこれを試すことができる場所誰かが私を修正することができます

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; 
関連する問題