5

我使用在 Centos 6.0 64 位上运行 Apache 的 Mono 2.11.1 构建来运行一个名为 Provisionning 的 Web 服务,它与 Asterisk 交互。我需要调用并执行一个 shell 命令来转换音频文件,称为 Sox。问题是我收到此错误消息:

System.ServiceModel.FaultException: System.ComponentModel.Win32Exception: ApplicationName='sox.sh', CommandLine='/var/lib/asterisk/sounds/4/chimes.wav /var/lib/asterisk/sounds/4/chimes_sox.wav', CurrentDirectory='/var/www/html/vms/bin/', Native error= Cannot find the specified file
 at System.Diagnostics.Process.Start_noshell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in <filename unknown>:0
 at System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in <filename unknown>:0
 at System.Diagnostics.Process.Start (System.Diagnostics.ProcessStartInfo startInfo) [0x00000] in <filename unknown>:0
 at Provisionning.VMSWS.ShellExec (System.String cmd, System.String path, System.String parms, System.Int32& exit_code) [0x00000] in <filename unknown>:0
 at Provisionning.VMSWS.SoxConvert (System.String fileName, System.String targetDir) [0x00000] in <filename unknown>:0
 at Provisionning.VMSWS.UploadFile (System.String username, System.String password, System.Byte[] f, System.String fileName) [0x00000] in <filename unknown>:0
 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
 at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 

如果我直接指定位于 /usr/bin 上的 sox 命令,不带任何参数,我会从 sox 应用程序中获得默认的“未指定参数”消息。如果我用两个参数指定 sox 命令,我会收到我粘贴的相同错误消息。为了传递和减少一些可能性,我在 web 服务的 bin 目录中创建了一个 shell 脚本,它执行带有一些参数的 sox 命令。手动执行 sox.sh 脚本,一切正常。从 web 服务的代码执行 sox.sh 脚本,我得到了指定的相同错误。

shell执行过程方法如下:

     protected String ShellExec(string cmd,string path,string parms,out int exit_code)
    {
        System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(cmd, parms);
        psi.RedirectStandardOutput = true;
        psi.UseShellExecute = false;
        psi.WorkingDirectory = path;

        System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);
        string tool_output = p.StandardOutput.ReadToEnd();
        p.WaitForExit();

        exit_code = p.ExitCode;
        return tool_output;
    }

这很简单

有什么线索吗?我真的无法理解缺少什么......

TIA

沙鲁阿

4

1 回答 1

2

尝试将完整路径传递给 sox.sh。

还要确保您#!/bin/sh在 shell 脚本中具有第一行。

于 2012-06-25T07:48:52.837 回答