我在写一个转换视频的程序,做成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文件执行,都是在那一步停止,这会是什么问题啊??我查了很多的资料,就是没有这方面的,高手们请解决啊!!!
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文件执行,都是在那一步停止,这会是什么问题啊??我查了很多的资料,就是没有这方面的,高手们请解决啊!!!
解决方案 »
- 如何用Gridview实现以下的页面效果?
- 怎么用函数实现两个字符串交换
- 请教实现webbrowser中idispatch接口的invoke方法
- 请问下如何查动态EXCEL表名
- 无法安装或运行此应用程序。该应用程序要求首先在“全局程序集缓存(GAC)”中安装程序集stdole版本7.0.3300.0
- petshop.msi怎么才能变成看到那种源代码的文件格式啊???
- 使用C#怎样在一定范围的数中随即选择出一个数,谢谢
- 从sqlserver2000中读取image类型数据并在picturebox中显示的问题
- 北京公司急需NET编程人员,全职
- 救命啊~用ListView删除一行选中的数据
- datagridview中的datapropertyname问题
- 解决在序列化时内存溢出问题
还怎么能得到输出呢? (myResult = process.StandardOutput.ReadToEnd(); )
直接调用mencoder也是一样的to wdgphc :
已经测试过小饰品文件可以得到输出,只是在大视频文件转换的过程中会卡死在这个输出语句上。这时候去看转换结果是一个还没有转换完的文件。而,关闭调试程序后,转换结果会自动的显示正常完成转换的文件。
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();
如果要处理的文件很大,需要的时间会长.
试过了,一样的。会卡死在
myResult = process.StandardOutput.ReadToEnd();
这句上不动。文件只转换了一部分,刷新也是一样。
停止运行后一两秒钟,没有被转换完成的文件自动刷新成已经转换完成的文件。
用bat文件也是一样的,多线程也是一样to Macosx :
在执行转换的过程中卡住了,输出语句就是转换信息输出,但是每次不一定是在同一行输出的时候卡住的(因为卡的时候生成的文件大小是不一样的)。因为有几百行输出,我不能跟到具体卡在那一行输出上了。
// 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);
}
}
}
}
经过测试,一样会卡,而且停止调试后转换到一半的文件被锁定了,不能删除。
命令行就行 process 就不行。很奇怪。
我也碰到一样的问题http://www.jiamaocode.com/Cts/1031.html测试了可以搞定