0

I want to open a bat file by c#.

private void button1_Click(object sender, EventArgs e)
{
    string cmd_p1 = @"ffmpeg -re -stream_loop -1 -i ";
    string strMediaSource = txtMediaSource.Text.Trim();
    string cmd_p2 = " -r 30 -c:v libx264 -x264-params keyint=60 -b:v 1000k -acodec libmp3lame -b:a 128k -ar 44100 -threads 0 -minrate 1000k -maxrate 1000k -bufsize 500k -f flv \"rtmp://rtmp-api.facebook.com:80/rtmp/";
    string strKey = txtKey.Text.Trim();

    StreamWriter sw = new StreamWriter("test.bat");
    sw.WriteLine(cmd_p1 + strMediaSource + cmd_p2 + strKey + "\"");
    sw.Close();
    Process p = new Process();
    p.StartInfo.FileName = "test.bat";
    p.Start();                       
}

But it's closed immediately. How can i keep it display.

Mighty Badaboom
  • 5,609
  • 5
  • 27
  • 47
  • Create the batch file and then execute it from a command prompt, I'll hazard a guess that an error message is displayed. – Lasse V. Karlsen Jul 11 '17 at 13:51
  • 2
    Why do you go through the trouble of creating a batch file instead of simply starting the process with the desired arguments? – Filburt Jul 11 '17 at 13:51
  • Add `pause` at the last line. – i486 Jul 11 '17 at 13:54
  • See a way to delay the close here: https://stackoverflow.com/questions/1672338/how-to-sleep-for-5-seconds-in-windowss-command-prompt-or-dos – Zelter Ady Jul 11 '17 at 13:56
  • Thank for your help. My issue is "i want to open ffmpeg.exe in folder D:\LiveStream, in this folder i use shift + right click -> open command prompt here. After that i want to patse a code to this command prompt. – Phạm Đức Trung Jul 11 '17 at 15:55

0 Answers0