5

i use Mono 2.11.1 build running Apache on Centos 6.0 64bits, to run a webservice named Provisionning, that interacts with Asterisk. I need to call and execute a shell command to convert audio files , called Sox . The problem is that i'm getting this error message:

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 

If i specify directly the sox command located on /usr/bin , without any argument, i get the default "no-arguments specified" message from the sox application. If i specify the sox command with both arguments, i get the same error message i pasted up. To pass and cut down some possibilities, i created a shell script located in the webservice's bin directory which executes the sox command with some arguments. Manually executing the sox.sh script , everything is ok. Executing the sox.sh script from the webservice's code, i get the same error specified up.

The shell execution process method is as follows:

     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;
    }

which is pretty simple

Any clue? i really cannot understand what is missing....

TIA

SCharrua

Botz3000
  • 39,020
  • 8
  • 103
  • 127
scharrua
  • 73
  • 2
  • 5

1 Answers1

2

Try passing the full path to sox.sh.

Also make sure you have #!/bin/sh as the first line in your shell script.

Rolf Bjarne Kvinge
  • 19,253
  • 2
  • 42
  • 86
  • Hello Rolf, thanks for your anwser. In fact, the full path is set by the path parameter in ShellExec method, which sets the value to the PropertyStartInfo's WorkingDirectory property. I also tested a simple sox.sh script which all it does is to do a "dir" and it works correctly. If i run the sox.sh script to convert audio files, the result is as showed on my 1st post.... – scharrua Jun 25 '12 at 15:41
  • 1
    Unless the current directory is in PATH, you shouldn't be able to execute scripts from the current directory. Try this: `System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(Path.Combine (path, cmd), parms);` – Rolf Bjarne Kvinge Jun 25 '12 at 20:28