【发布时间】:2012-06-30 10:38:00
【问题描述】:
我正在编写一个使用隐藏控制台 CMD 的程序。从编解码器“ffmpeg”开始。转换时总是得到反馈。
我希望控制台每 1 秒充电一次。不幸的是,互联网上所有可用的代码都遵循转换后退款的原则,我想一直看着你发生了什么。
public void ExecuteCommandSync(object command)
{
try
{
// create the ProcessStartInfo using "cmd" as the program to be run,
// and "/c " as the parameters.
// Incidentally, /c tells cmd that we want it to execute the command that follows,
// and then exit.
System.Diagnostics.ProcessStartInfo procStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();
// Display the command output.
Console.WriteLine(result);
}
catch (Exception objException)
{
// Log the exception
}
}
【问题讨论】:
-
这是谷歌翻译制作的吗? “退款”部分非常可疑。
-
小费在这里 :))