我在写一个转换视频的程序,做成windows服务,但是在   
  Process   process   =   new   Process();   
                                  process.StartInfo.FileName   =   "cmd.exe";   
                                  process.StartInfo.UseShellExecute   =   false;   
                                  process.StartInfo.RedirectStandardInput   =   true;   
                                  process.StartInfo.RedirectStandardOutput   =   true;   
                                  process.StartInfo.RedirectStandardError   =   true;   
                                  process.StartInfo.CreateNoWindow   =   true;   
                                  process.Start();   
                                    
                                  process.StandardInput.WriteLine(myCommon);   
                                  process.StandardInput.WriteLine("exit");   
                                    
                                  myResult   =   process.StandardOutput.ReadToEnd();   
                                  process.WaitForExit();   
                                  process.Close();   
    
  调用的命令为:   
  D:\logService2news\logService2\bin\Debug\mencoder.exe   D:\mv.asf   -o   D:\mv.flv   -of   lavf   -oac   mp3lame   -lameopts   abr:br=56   -ovc   lavc   -lavcopts   vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3   -sws   3   -vf   scale=320:240,expand=320:240:::1,crop=320:240:0:0   -ofps   30   -srate   22050   -lavfopts   i_certify_that_my_video_stream_does_not_use_b_frames   
  但是运行到process.StandardOutput.ReadToEnd();就没有反应了,我结束该windows服务以后,这条命令自动会接着执行!!   
  在运行里执行该命令没有任何的问题,在执行的时候会输出很多转换的状态.但是只要用c#调用就不行,无论是直接命令还是写成BAT文件执行,都是在那一步停止,这会是什么问题啊??我查了很多的资料,就是没有这方面的,高手们请解决啊!!! 

解决方案 »

  1.   

    调用CMD做什么呢!直接调用D:\logService2news\logService2\bin\Debug\mencoder.exe  这个程序。
      

  2.   

    你都写了exit 关闭cmd环境了.(process.StandardInput.WriteLine("exit");  )
    还怎么能得到输出呢? (myResult  =  process.StandardOutput.ReadToEnd();  )
      

  3.   

    to bidisty :
    直接调用mencoder也是一样的to wdgphc :
    已经测试过小饰品文件可以得到输出,只是在大视频文件转换的过程中会卡死在这个输出语句上。这时候去看转换结果是一个还没有转换完的文件。而,关闭调试程序后,转换结果会自动的显示正常完成转换的文件。
      

  4.   

    试试这样:Process  process  =  new  Process();  
                                      process.StartInfo.FileName  =  "D:\\logService2news\\logService2\\bin\\Debug\\mencoder.exe";  
                                      process.StartInfo.UseShellExecute  =  false;  
                                      process.StartInfo.RedirectStandardInput  =  true;  
                                      process.StartInfo.RedirectStandardOutput  =  true;  
                                      process.StartInfo.RedirectStandardError  =  true;  
                                      process.StartInfo.CreateNoWindow  =  true;  
                                      process.StartInfo.Arguments = "...你自己填吧"                                  process.Start();  
                                        
                                      myResult  =  process.StandardOutput.ReadToEnd();  
                                      process.WaitForExit();  
                                      process.Close();  
    如果要处理的文件很大,需要的时间会长.
      

  5.   

    to coldwinter_stone :
    试过了,一样的。会卡死在 
    myResult  =  process.StandardOutput.ReadToEnd();  
    这句上不动。文件只转换了一部分,刷新也是一样。
    停止运行后一两秒钟,没有被转换完成的文件自动刷新成已经转换完成的文件。
      

  6.   

    使用bat文件,如果你的代码执行时间很久,是用多Thread
      

  7.   

    to jietuan :
    用bat文件也是一样的,多线程也是一样to Macosx :
    在执行转换的过程中卡住了,输出语句就是转换信息输出,但是每次不一定是在同一行输出的时候卡住的(因为卡的时候生成的文件大小是不一样的)。因为有几百行输出,我不能跟到具体卡在那一行输出上了。
      

  8.   

    试试异步行不行 MSDN范例 要是能调试moncoder就好了
    // Define the namespaces used by this sample.
    using System;
    using System.Text;
    using System.IO;
    using System.Diagnostics;
    using System.Threading;
    using System.ComponentModel;namespace ProcessAsyncStreamSamples
    {
        class SortOutputRedirection
        {
            // Define static variables shared by class methods.
            private static StringBuilder sortOutput = null;
            private static int numOutputLines = 0;        public static void SortInputListText()
            {
                // Initialize the process and its StartInfo properties.
                // The sort command is a console application that
                // reads and sorts text input.            Process sortProcess;
                sortProcess = new Process();
                sortProcess.StartInfo.FileName = "Sort.exe";            // Set UseShellExecute to false for redirection.
                sortProcess.StartInfo.UseShellExecute = false;            // Redirect the standard output of the sort command.  
                // This stream is read asynchronously using an event handler.
                sortProcess.StartInfo.RedirectStandardOutput = true;
                sortOutput = new StringBuilder("");            // Set our event handler to asynchronously read the sort output.
                sortProcess.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler);            // Redirect standard input as well.  This stream
                // is used synchronously.
                sortProcess.StartInfo.RedirectStandardInput = true;            // Start the process.
                sortProcess.Start();            // Use a stream writer to synchronously write the sort input.
                StreamWriter sortStreamWriter = sortProcess.StandardInput;            // Start the asynchronous read of the sort output stream.
                sortProcess.BeginOutputReadLine();            // Prompt the user for input text lines.  Write each 
                // line to the redirected input stream of the sort command.
                Console.WriteLine("Ready to sort up to 50 lines of text");            String inputText;
                int numInputLines = 0;
                do 
                {
                    Console.WriteLine("Enter a text line (or press the Enter key to stop):");                inputText = Console.ReadLine();
                    if (!String.IsNullOrEmpty(inputText))
                    {
                        numInputLines ++;
                        sortStreamWriter.WriteLine(inputText);
                    }
                }
                while (!String.IsNullOrEmpty(inputText) && (numInputLines < 50));
                Console.WriteLine("<end of input stream>");
                Console.WriteLine();            // End the input stream to the sort command.
                sortStreamWriter.Close();            // Wait for the sort process to write the sorted text lines.
                sortProcess.WaitForExit();            if (numOutputLines > 0)
                {
                    // Write the formatted and sorted output to the console.
                    Console.WriteLine(" Sort results = {0} sorted text line(s) ", 
                        numOutputLines);
                    Console.WriteLine("----------");
                    Console.WriteLine(sortOutput);
                }
                else 
                {
                    Console.WriteLine(" No input lines were sorted.");
                }            sortProcess.Close();
            }        private static void SortOutputHandler(object sendingProcess, 
                DataReceivedEventArgs outLine)
            {
                // Collect the sort command output.
                if (!String.IsNullOrEmpty(outLine.Data))
                {
                    numOutputLines++;                // Add the text to the collected output.
                    sortOutput.Append(Environment.NewLine + 
                        "[" + numOutputLines.ToString() + "] - " + outLine.Data);
                }
            }
        }
    }
      

  9.   

    to Macosx :
    经过测试,一样会卡,而且停止调试后转换到一半的文件被锁定了,不能删除。
      

  10.   

    goffiecer 我也这样,好几天了不知道哪里问题
    命令行就行 process 就不行。很奇怪。
      

  11.   

    缓冲区爆了
    我也碰到一样的问题http://www.jiamaocode.com/Cts/1031.html测试了可以搞定