2017-09-24 7 views
1

나는 C#에서 bash를 통해 cygwin 명령을 실행하려고 시도하고 결과를 읽기 명령으로 열어 두려고합니다. 내 코드가 bash를 열고 곧 닫는 것 같습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?C#에서 cygwin 명령을 실행하고 열어 두는 방법은 무엇입니까?

static void Main(string[] args) 
{ 
    Process bashProcess = new Process(); 
    bashProcess.StartInfo.FileName = @"C:\cygwin64\bin\bash.exe"; 
    bashProcess.StartInfo.Arguments = "-l -c echo blah; read"; 
    bashProcess.StartInfo.UseShellExecute = true; 
    bashProcess.Start(); 


    bashProcess.WaitForExit(); 
    System.Console.WriteLine("Exit Code: {0}", bashProcess.ExitCode); 

    System.Console.WriteLine("Press enter to exit..."); 
    System.Console.ReadLine(); 
} 

답변

1

방금 ​​해결책을 찾았습니다. 작은 따옴표로 전체 명령을 묶으면 제대로 작동합니다.

bashProcess.StartInfo.Arguments = "-l -c 'echo blah; read'"; 
+1

와' "-l -c '에코 $ 0; 읽기' 'ㅋ'을"동일한 출력을 제공한다': 그래서

bashProcess.StartInfo.Arguments = "-l -c echo blah; read"; 

는 다음과 같이 교체해야합니다. "blah"문자열은 이제 0 번째 명령 줄 인수입니다. – eryksun