2010-03-03 5 views
2

다음 코드를 실행하고 싶습니다.stdin에 명령을 보내고 전송 끝을 보내기 (Ctrl + D)

당신이 끝날 때까지 내가 부르고있는 응용 프로그램은 User-Name = albert와 같은 명령, 다음 명령 등을 기대합니다.

명령 줄에서 수동으로 입력하려면 command를 입력하고 Enter 키를 누른 다음 command 키를 입력하고 Enter 키를 누릅니다. 끝에서 오른쪽 마지막 명령 다음에 ENTER를 누른 후 Ctrl + D를 눌러 끝내면 프로그램을 실행하고 발생한 일을 다시 알려줍니다.

는 명령이 잘못 입력하면 응용 프로그램이 그래서 내가 아래 일을하고있어 수동으로의 입력 시뮬레이션되어 바로 포맷되지 않았습니다 라인 ...

을 보낸 것을 의미한다 "= 기대"라고, 하나의 명령, 새로운 라인, 하나의 명령, 새로운 라인 등, 마지막까지, 그리고 난 마지막 명령 뒤에 Ctrl + D를 추가합니다. 이것은 작동하지 않으며 프로그램은 "expecting ="이라고 말합니다.

명백한 문제가 있습니까?

감사합니다. 알버트

 // CREATE DISCONNECT FILE 
     StringBuilder sb = new StringBuilder(); 
     sb.AppendLine("User-Name=" + this.userName); 
     sb.AppendLine("Acct-Session-Id=" + this.sessionID); 
     sb.AppendLine("NAS-IP-Address=" + Setting.Item["EDGE.NASIP"]); 
     sb.AppendLine("Framed-IP-Address=" + this.currentIP); 
     sb.Append("/x4"); 
     System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo(); 
     procStartInfo.WorkingDirectory = radclientPath.Substring(0, radclientPath.LastIndexOf("\\")); 
     procStartInfo.FileName = radclientPath; 
     procStartInfo.Arguments = @"-r 1 -d ..\etc\raddb -x 192.168.1.240:3799 disconnect password"; 
     procStartInfo.RedirectStandardInput = true; 
     procStartInfo.RedirectStandardError = true; 
     procStartInfo.RedirectStandardOutput = true; 
     procStartInfo.UseShellExecute = false; 

     System.Diagnostics.Process proc = System.Diagnostics.Process.Start(procStartInfo); 

     proc.StandardInput.Write(sb.ToString()); 
     proc.WaitForExit(5000); 

     if (proc.HasExited) 
     { 
      System.IO.File.WriteAllText(@"D:\temp.txt", proc.StandardOutput.ReadToEnd()); 
      System.IO.File.WriteAllText(@"D:\temp2.txt", proc.StandardError.ReadToEnd()); 
      string message = proc.StandardOutput.ReadToEnd() + "\n---\nErrors:\n---\n" + proc.StandardError.ReadToEnd(); 
      return message; 
     } 
     System.IO.File.WriteAllText(@"D:\temp.txt", proc.StandardOutput.ReadToEnd()); 
     System.IO.File.WriteAllText(@"D:\temp2.txt", proc.StandardError.ReadToEnd()); 
     return ""; 
    } 

또한 작은 따옴표와 중 수 (\ X04) 아무것도를 선도 0으로 그것을 시도, 그래서 나는 텍스트 파일로 프로그램에 전송해야 무엇을 작성했습니다. 그런 다음 아래와 같은 명령 줄 매개 변수를 사용하여 프로그램을 실행했습니다. 전체 텍스트 파일에있는 내용을 복사하여 명령 프롬프트에 붙여 넣으면 제대로 작동합니다. 확실하지

 StringBuilder sb = new StringBuilder(); 
     sb.AppendLine("User-Name=" + this.userName); 
     sb.Append('\x04'); 
     System.IO.File.WriteAllText(@"D:\input.txt", sb.ToString()); 
     System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo(); 
     procStartInfo.WorkingDirectory = radclientPath.Substring(0, radclientPath.LastIndexOf("\\")); 
     procStartInfo.FileName = radclientPath; 
     procStartInfo.Arguments = @"-r 1 -d ..\etc\raddb -x 192.168.1.240:3799 disconnect password"; 
     procStartInfo.RedirectStandardInput = true; 
     procStartInfo.RedirectStandardError = true; 
     procStartInfo.RedirectStandardOutput = true; 
     procStartInfo.UseShellExecute = false; 
     System.Diagnostics.Process proc = System.Diagnostics.Process.Start(procStartInfo); 
     proc.StandardInput.Write(sb.ToString()); 
     proc.WaitForExit(5000); 

답변

0
sb.Append("/x4"); 

이 제어-D

아마도

당신이

당신은 "\x04"를 추가 작성해야
sb.Append("\x04"); 
+0

내 원래 코드에 \ x4가있었습니다. 죄송합니다. 이것은 게시물을 만드는 오타였습니다. Il은 4 앞에 0을 추가하고 다시보고하십시오! 고마워, 알버트 – Albert

+0

안녕하세요, 방금 위를 업데이트 해주세요.보세요 ... – Albert

+0

어딘가에 인코딩 문제가 있는지 궁금합니다 ... – Albert

2

을 의미하지 않습니다 .. 표준 입력에 제대로 전송되지 왜 , 백 슬라 (\)

자세한 내용은 documentation (문자열 이스케이프 시퀀스 섹션)

관련 문제