2009-08-15 4 views
2

encryptFile 파일에서 if 문을 true로 변경하면 코드가 예상대로 작동합니다. 그러나 나는 못생긴 화면에 콘솔 창을 얻는다. FileListName을 빈 아카이브로 압축하면 false가됩니다. 왜?7z 파일이 플러시됩니다. 파일을 압축하지 않음

 using (TextWriter tw = (TextWriter)new StreamWriter(FileListName)) 
     { 
      writeFilename(tw, t, "."); 
      tw.Flush(); 
      tw.Close(); 
     } 
     encryptFile(FileListName, dst + Path.GetFileName(FileListName)+".7z", password, null); 




    void encryptFile(string srcFile, string dstFile, string pass, int? compressLevel) 
    { 
     string line; 
     var p = new Process(); 
     line = string.Format("a -t7z \"{0}\" \"{1}\" -mhe -p{2} ", dstFile, srcFile, pass); 
     if (compressLevel != null) 
      line += string.Format("-mx{0} ", compressLevel); 
     p.StartInfo.Arguments = line; 
     p.StartInfo.FileName = @"C:\Program Files\7-Zip\7z.exe"; 
     p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
     if (false) 
     { 
      p.StartInfo.UseShellExecute = false; 
      p.StartInfo.RedirectStandardOutput = true; 
      p.StartInfo.RedirectStandardError = true; 
      p.Start(); 

      var sr = p.StandardOutput; 
      var err = p.StandardError; 
      Console.Write(sr.ReadToEnd()); 
      Console.Write(err.ReadToEnd()); 
     } 
     else 
      p.Start(); 
    } 

답변

1

당신이 p.Start()p.WaitForExit()를 호출 할 필요가

p.StartInfo.CreateNoWindow = true; 
1

시도해야 윈도우를 제거합니다. 설명서를 참조하십시오 :

당신이 if (true)ReadToEnd() 통화 효과적으로 프로세스가 어쨌든 종료 될 때까지 기다려야 강제한다는 것입니다 때 작동하는 이유를.

+0

Bam, 작동합니다. 그게 완벽하게 이해가 되네요. 특히 encryptFile 다음에 delete (FileListName)를 써주세요. –

+0

멋지다. :) – ars

관련 문제