Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mono shell execute

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

like image 708
scharrua Avatar asked Nov 03 '22 21:11

scharrua


1 Answers

Try passing the full path to sox.sh.

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

like image 191
Rolf Bjarne Kvinge Avatar answered Nov 09 '22 13:11

Rolf Bjarne Kvinge