Prevent child process from showing a shell window in c#

拈花ヽ惹草 提交于 2019-12-07 14:18:41

问题


I'm using ffmpeg to compile videos, and I'd like to prevent it from displaying a console when performing actions.

Here's how I start ffmpeg:

ProcessStartInfo si = new ProcessStartInfo();
si.Arguments = string.Format("-y -loop 1 -t " + DucationToString(frameDuration) + " -r 25 -f image2 -i \"{0}\" \"{1}\"",
                             item.Value, otpt);
si.FileName = "ffmpeg";
si.UseShellExecute = false;

Process.Start(si).WaitForExit();

No matter the settings I try in ProcessStartInfo, the console always shows up.

How do I prevent the console from being shown when creating child process?


回答1:


You should try to use

ProcessStartInfo si = new ProcessStartInfo();
si.WindowStyle = ProcessWindowStyle.Hidden;
si.CreateNoWindow = true;
si.UseShellExecute = false;

MSDN refs




回答2:


Set ProcessStartInfo.CreateNoWindow to true.

Note that:

To use ProcessWindowStyle.Hidden or ProcessStartInfo.CreateNoWindow the ProcessStartInfo.UseShellExecute property must be false.




回答3:


Have you added this in your code

    si.CreateNoWindow = true;
    si.RedirectStandardOutput = true;


来源:https://stackoverflow.com/questions/11538848/prevent-child-process-from-showing-a-shell-window-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!