1
try
{
        string filename = "E:\\sox-14-4-0\\mysamplevoice.wav";
        Process p = new Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.FileName = "E:\\sox-14-4-0\\sox.exe ";
        p.StartInfo.Arguments = filename + " -n stat";
        p.Start();
        string output = p.StandardOutput.ReadToEnd();
        p.WaitForExit();
}
catch(Exception Ex)
{
        Console.WriteLine(Ex.Message);
}

出力は常に空です。コマンド プロンプトでそのコマンドを実行するとsox、次のような応答が返されます。

E:\sox-14-4-0>sox mysamplevoice.wav -n stat
Samples read:             26640
Length (seconds):      3.330000
Scaled by:         2147483647.0
Maximum amplitude:     0.515625
Minimum amplitude:    -0.734375
Midline amplitude:    -0.109375
Mean    norm:          0.058691
Mean    amplitude:     0.000122
RMS     amplitude:     0.101146
Maximum delta:         0.550781
Minimum delta:         0.000000
Mean    delta:         0.021387
RMS     delta:         0.041831
Rough   frequency:          526
Volume adjustment:        1.362

C# で同じコマンドを実行すると、同じ結果が得られますが、「出力」の値は空です。

4

2 に答える 2

4

sox.exe は STDERR ではなく STDOUT に書き込みますか?

OutputDataReceived代わりにイベントを使用してデータを読み取ってみることができます。

string filename = "E:\\sox-14-4-0\\mysamplevoice.wav";
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = "E:\\sox-14-4-0\\sox.exe ";
p.StartInfo.Arguments = filename + " -n stat";

p.OutputDataReceived += process_OutputDataReceived;
p.ErrorDataReceived += process_ErrorDataReceived;

p.Start();
p.BeginErrorReadLine();
p.BeginOutputReadLine();


void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
    string s = e.Data;
}

void process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
    string s = e.Data;
}
于 2012-09-12T09:35:55.497 に答える