2016-04-18 49 views
0

私はsoxをc#programのprocessを呼び出して使用しています。私はWaitForExitやStartメソッドにぶら下がっていることはよく知られていますが、私はそれに対処できません。あなたは、標準出力が非同期に処理されますが、まだプログラムはタイムアウトが設定されている場合でもWaitForExit(でハング見ることができるようにSoxを使用して標準出力にプッシュするときにWaitForExitでプロセスがハングアップする

using (Process process = new Process()) 
{ 
    process.StartInfo.FileName = _soxExePath; 
    process.StartInfo.Arguments = _task.Arguments.RemoveFirstOccurence("sox"); 
    process.StartInfo.UseShellExecute = false; 
    process.StartInfo.RedirectStandardOutput = true; 
    process.StartInfo.RedirectStandardError = true; 

    StringBuilder output = new StringBuilder(); 
    StringBuilder error = new StringBuilder(); 

    using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false)) 
    using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false)) 
    { 
     process.OutputDataReceived += (sender, e) => 
     { 
      if (e.Data == null) 
      { 
       outputWaitHandle.Set(); 
      } 
      else 
      { 
       output.AppendLine(e.Data); 
      } 
     }; 
     process.ErrorDataReceived += (sender, e) => 
     { 
      if (e.Data == null) 
      { 
       errorWaitHandle.Set(); 
      } 
      else 
      { 
       error.AppendLine(e.Data); 
      } 
     }; 

     process.Start(); 

     process.BeginOutputReadLine(); 
     process.BeginErrorReadLine(); 

     if (process.WaitForExit(timeout) && 
      outputWaitHandle.WaitOne(timeout) && 
      errorWaitHandle.WaitOne(timeout)) 
     { 
      result = process.ExitCode == 0; 
     } 
     else 
     { 
      // Timed out. 
     } 
    } 
} 

:たぶん私はthis topicで最高の定格の答えから&ペーストをコピーしている(プロセスを実行するためのコードreponsibleからスタート私は、WindowsのCMD処理にまったく同じコマンドを入力すると、それは大きな操作ではありませんので)100000まで。秒未満かかります。

sox --combine mix 1.wav 2.wav 3.wav -p | sox - --combine concatenate 4.wav output.wav << causing problem 

私はそれがstdoutに最初の操作を作成しているソックスによって引き起こされる知っています。すぐにファイルに保存するコマンドを試しても問題ありません。

sox --combine mix 1.wav 2.wav 3.wav output.wav << no problem 
+0

soxプログラムからのログはありますか? –

答えて

0

答えはあなたがsoxを呼び出す方法にあります。あなたが期待していた出力が完全に得られていないと推測しています。あなたはいけない任意の出力と入力を送受信するためのイベントを上げるの有効化、およびあなたが唯一の出力データを受信設定する必要があるのをオン

process.StartInfo.FileName = _soxExePath; 
process.StartInfo.Arguments = _task.Arguments.RemoveFirstOccurence("sox"); 
process.StartInfo.UseShellExecute = false; 
process.StartInfo.RedirectStandardOutput = true; 
process.StartInfo.RedirectStandardError = true; 
process.EnableRaisingEvents = true; 
    //<set event handlers here> 
process.Exited += // define what to do to clear up 
process.Start(); 

Theresの2つの違い、一つは、それ新しいものを送っているように見えます。また、出口を聞いて、事実をすべて処理することができます..あなたのアプリが終了したと聞きたいと思っています。

0

私の解決方法はhereです。プロセスとしてcmdを呼び出し、パスを渡すだけです。プロセスargsとしての実行可能ファイルとsoxの引数

関連する問題