cmd windows not showing output

99封情书 提交于 2021-02-08 10:42:23

问题


I'm having an issue where my cmd windows is just blank when executed from code. I've searched here and there for some solutions. And tried a few different things myself.

Running it with a normal .bat file works just fine.. But just not from my C# application.

Note: the ffmpeg is being run perfectly, but just not showing anything in the cmd window when executed from code.

image at the bottom. I'll update this if I find a solution.. Unless you guys do it first ;)

Code:

      private async void RunFfmpeg()
    {
        await Task.Run(() =>
        {
        String destFolder = null;
        String sourceFolder = null;
        int listCount = 0;

        this.Dispatcher.Invoke(() =>
        {
            destFolder = textDest.Text;
            sourceFolder = textSource.Text;
            listCount = listFiles.Items.Count;
        });



        foreach (FileInfo fileC in listFiles.Items)
        {
            //Changing old extension to mp4
            string oldFileName = fileC.ToString();
            string newFileName = null;

            string[] extension = oldFileName.Split('.');

            newFileName = extension[0] + ".mp4";

            string newDir = destFolder + "\\" + extension[0];
            DirectoryInfo createDir = new DirectoryInfo(newDir);

            if (!createDir.Exists)
            {
                createDir.Create();
            }

            //Gathering folders and all I need...
            string output = "\"" + destFolder + "\\" + extension[0] + "\\" + newFileName + "\"";
            string input = "\"" + sourceFolder + "\\" + oldFileName + "\"";

                var startInfo = new System.Diagnostics.ProcessStartInfo
                {
                    FileName = "cmd.exe",
                    //Arguments = $"-i {input} {output}",
                    Arguments = $"/c ffmpeg -i {input}" + " -c:a copy -c:v copy " + $"{output}",
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow = false,
                    WorkingDirectory = Directory.GetCurrentDirectory()
                };
                Process p = new Process();
                p.StartInfo = startInfo;
                p.OutputDataReceived += P_OutputDataReceived;
                p.Start();
                p.WaitForExit();
            }
        });
    }

Here is where I read the output:

        private void P_OutputDataReceived(object sender, DataReceivedEventArgs e)
    {
        this.Dispatcher.Invoke(() =>
        {
            //string cmdBox = cmdOutput.Text;
            //cmdOutput.AppendText(cmdBox);
            //cmdOutput.Clear();
            cmdOutput.AppendText(e.Data);
        });
    }

Images showing blank cmd

来源:https://stackoverflow.com/questions/55245315/cmd-windows-not-showing-output

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