This is a migrated thread and some comments may be shown as answers.

Call a exe file from server

0 Answers 85 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nelson
Top achievements
Rank 1
Nelson asked on 23 Apr 2012, 10:35 AM
Hi there,

I´m trying call in my silverlight application some exe file to convert mp3 to ogg.

To do that, I create a process and call the .exe file like this:

 string caminhoPastaTemp = caminhoPathTemp;
                int timeout = 9000;

                if (!Directory.Exists(caminhoPastaTemp))
                    throw new Exception("Erro: caminho da pasta temporária incorrecto! [" + caminhoPastaTemp + "]");

                //parar processos que estejam a correr
                Process[] listaProcessos;
                listaProcessos = Process.GetProcessesByName("BeSweet");
                
                foreach (Process p in listaProcessos)
                {
                    p.WaitForExit();
                    if (!p.HasExited)
                    {
                        p.Kill();
                        p.Dispose();
                        p.Close();
                    }
                }

                //obter sessionid
                int sessionid = 0;
                Process[] procs = Process.GetProcesses();
                for (int i = 0; i < procs.Length; i++)
                {
                    if (procs[i].ProcessName.ToUpper().Equals("EXPLORER"))
                        sessionid = procs[i].SessionId;
                }


                //iniciar processo que executa beSweet para conversão
                Process proc = new Process();
                proc.StartInfo.WorkingDirectory = caminhoPastaTemp;
                proc.StartInfo.RedirectStandardOutput = true;
                
                
                string strArgumentos = Util.DevolvePathRaizAplicacao() +"\\ConverteGravacao\\BeSweet.exe -core ( -input " + nomeFicheiroEntrada + " -output " + nomeFicheiroSaida + " -logfilea log.log ) -ogg( -b 160 )";//+ " -logfilea \"%1_CONV_LOG.log\"
                //string strArgumentos = " -core ( -input " + nomeFicheiroEntrada + " -output " + nomeFicheiroSaida + " -logfilea log.log ) -ogg(  )";
                
                
                proc.StartInfo.Arguments = strArgumentos;
                proc.StartInfo.CreateNoWindow = false;
                proc.StartInfo.FileName = Util.DevolvePathRaizAplicacao() + "\\ConverteGravacao\\BeSweet.exe";
                //proc.StartInfo.FileName = "calc.exe";
                proc.StartInfo.RedirectStandardError = true;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.UseShellExecute = false;



                proc.Start();

                proc.WaitForExit(timeout);
                

                //verificar se processo terminou
                listaProcessos = Process.GetProcessesByName("BeSweet");
                foreach (Process p in listaProcessos)
                {
                     p.WaitForExit(timeout);
                    if (!p.HasExited)
                    {
                        p.Kill();
                        p.Dispose();
                        p.Close();
                    }
                }
                proc.WaitForExit();
                proc.Dispose();

            }
            catch(Exception ex)
            {
                string erro = ex.Message;
            }

But the process finish unexpectedly and only convert 5 seconds of audio..always 5 seconds.

I tried increase timeout for huge values, but the problem is the same...

The folder have admin permissions, I execute this with admin permissions in VS2010, but the problem is the same..

Note that this code is running in server-side. Another thing, if I call the windows calculator for example, works good..

Can anyone tell me why happens this?

Thanks in advance.

Nelson

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
Nelson
Top achievements
Rank 1
Share this question
or