2017-09-26 9 views
0

CentOS 상자에 dotnet 코어 콘솔 응용 프로그램을 실행하고 있습니다. 아래의 코드는 일반적인 명령과 비슷한 "가동 시간"에 대해 실행 중입니다. 하지만 대한 실행하지 "lz4 -dc --no-스파 스 vnp.tar.lz4 | 타르 XF - Logs.pdf"dotnet 코어를 사용하여 CentOS에서 linux 명령을 실행하십시오.

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 파일을 추출하고 현재 위치에 저장 될 필요가있다 . 응용 프로그램이 리눅스 시스템에서 실행중인 경우 메신저

답변

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;