【问题标题】:Fail to run SoX using Process in C#在 C# 中使用 Process 无法运行 SoX
【发布时间】:2012-12-06 11:04:49
【问题描述】:

我正在尝试使用 SoX 将 MP3 文件转换为 GSM 编码的 WAV

执行此操作的 C# 代码是:

Console.WriteLine(Cfg.SoxPath); // bin/sox.exe
Console.WriteLine(args); // A rather long argument
var startInfo = new ProcessStartInfo();
startInfo.FileName = Cfg.SoxPath;
startInfo.Arguments = args;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = false;

using (Process soxProc = Process.Start(startInfo))
{
    soxProc.WaitForExit();
}

代码的输出是:

bin\sox.exe  
"D:\VoiceRecorder Soundfiles Storage\MP3 Storage\2012-12-05\227\1\20121205_203436_2103c60a0000134850bfa1bd2c99_8075598.mp3" -c 1 -r 8000 -e gsm-full-rate "temp\227_20120901\SW120006_349990195665213_040154700_20121205203436_20.wav"  
bin\sox.exe FAIL formats: can't open input file `8000': No such file or directory

是什么导致命令失败?

需要考虑的事项

  • 直接从 cmd 提示符执行该命令运行完美
  • 参数 (-c 1 -r 8000 -e gsm-full-rate) 是从 sql 服务器获取的
  • 对参数的微小更改(例如,将 -e 替换为 --encoding)可能会更改错误消息
  • 试过 .NET 3.0 和 4.0
  • 错误消息甚至包含不属于参数的字符 (can't open input file 'ûg')
  • 相同的参数总是导致相同的错误

【问题讨论】:

  • @leppie 恐怕单引号会产生同样的错误。值得一试

标签: c# processstartinfo


【解决方案1】:

我将“介于两者之间”的参数更改为:

-r 8k -e gsm-full-rate -c 1

即使参数相同,它也开始工作了,只是稍微调整了一下。
我仍然不知道为什么它不能在 .NET 中工作,而只能在这些编辑之前的命令行中工作。

但现在可以了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多