.net 单壳执行

.net 单壳执行,.net,web-services,mono,mod-mono,.net,Web Services,Mono,Mod Mono,我使用Centos 6.0 64位上运行Apache的Mono 2.11.1构建来运行名为Provisioning的Web服务,该服务与Asterisk交互。 我需要调用并执行一个shell命令来转换音频文件,称为Sox。问题是我收到了以下错误消息: System.ServiceModel.FaultException: System.ComponentModel.Win32Exception: ApplicationName='sox.sh', CommandLine='/var/lib/as

我使用Centos 6.0 64位上运行Apache的Mono 2.11.1构建来运行名为Provisioning的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 
这很简单

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

短暂性脑缺血发作


SCharrua

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


还要确保您有
#/bin/sh
作为shell脚本的第一行。

您是否尝试过使用/bin/sh来运行它?您好Rolf,谢谢您的帮助。事实上,完整路径是由ShellExec方法中的path参数设置的,该参数将值设置为PropertyStartInfo的WorkingDirectory属性。我还测试了一个简单的sox.sh脚本,它所做的只是执行一个“dir”,并且工作正常。如果我运行sox.sh脚本来转换音频文件,结果如我的第一篇文章所示……除非当前目录在PATH中,否则您将无法从当前目录执行脚本。尝试以下操作:
System.Diagnostics.ProcessStartInfo psi=new System.Diagnostics.ProcessStartInfo(Path.Combine(Path,cmd),parms)
     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;
    }