Sang, Chunwangchihan. Even though it is clear that there is no rain, the depths of the cloud also dip. Want to cross the Yellow River ice Sechuan, will go to Taihang snow full mountain. This song should only be in heaven, and the world would smell a few. The nostalgia of the bird, the Chi Mas of the forest. C # Several ways to start an external program:
1. Start an external program without waiting for it to exit.
2. Start the external program and wait for it to exit.
3. Start an external program and wait indefinitely for it to exit.
4. Launch an external program to monitor its exit through events.
Using System.Diagnostics;
private string appName = "Calc.exe";
<summary>
1. Start an external program without waiting for it to exit
</summary>
private void Button1_Click (object sender, EventArgs e)
{
Process.Start (AppName);
MessageBox.Show (String.Format ("external program {0} started to complete! ", This.appname), this. Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
//<summary>
//2. Start an external program and wait for it to exit
//</summary>
private void Button2_Click (object sender, Eve Ntargs e)
{
Try
{
Process proc = Process.Start (appName);
if (proc! = null)
{
Proc. WaitForExit (3000);
if (Proc. hasexited)
MessageBox.Show (String.Format ("external program {0} has exited! ", This.appname), this. Text,
MessageBoxButtons.OK, messageboxicon.information);
Else
{
//If the external program does not end the run, it is forcibly terminated.
Proc. Kill ();
MessageBox.Show (String.Format ("external program {0} was forcibly terminated! ", This.appname), this. Text,
MessageBoxButtons.OK, messageboxicon.exclamation);
}
}
}
catch (ArgumentException ex)
{
MessageBox.Show (ex). Message, this. Text,
MessageBoxButtons.OK, messageboxicon.error);
}
}
///<summary>
//3. Start an external program and wait indefinitely for its exit
//</summary>
private void Button3_Click (object send Er, EventArgs e)
{
Try
{
Process proc = Process.Start (appName);
if (proc! = null)
{
Proc. WaitForExit ();
MessageBox.Show (String.Format ("external program {0} has exited! ", This.appname), this. Text,
MessageBoxButtons.OK, messageboxicon.information);
}
}
catch (ArgumentException ex)
{
MessageBox.Show (ex). Message, this. Text,
MessageBoxButtons.OK, messageboxicon.error);
}
}
<summary>
4. Start an external program to monitor its exit through events
</summary>
private void Button4_Click (object sender, EventArgs e)
{
Try
{
Start an external program
Process proc = Process.Start (appName);
if (proc! = null)
{
Monitoring Process exit
Proc. EnableRaisingEvents = true;
Specifying Exit Event Methods
Proc. Exited + = new EventHandler (proc_exited);
}
}
catch (ArgumentException ex)
{
MessageBox.Show (ex. Message, this. Text,
MessageBoxButtons.OK, Messageboxicon.error);
}
}
<summary>
External program Exit Event
</summary>
void Proc_exited (object sender, EventArgs e)
{
MessageBox.Show (String.Format ("external program {0} has exited!) ", This.appname), this. Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Call CMD.exe in C #, execute DOS commands, encode FLV
Process P = new process ();
p.StartInfo.FileName = "cmd.exe";
P.startinfo.useshellexecute = false;
P.st Artinfo.redirectstandardinput = true;
P.startinfo.redirectstandardoutput = true;
P.startinfo.redirectstandarderror = true;
P.startinfo.createnowindow = true;
P.start ();
String Stroutput=null;
//P.standardinput.writeline ("CD D:\\flv\\mplayer");
//P.standardinput.writeline ("CD D:");
P.standardinput.writeline (String. Format ("D:\\flv\\mplayer\\mencoder \" c:\\vs.wmv\ "-o \" c:\\output.flv\ "-of lavf-lavfopts i_certify_that_my_video_ STREAM_DOES_NOT_USE_B_FRAMES-OAC mp3lame-lameopts ABR:BR=56-OVC lavc-lavcopts vcodec=flv:vbitrate={0}:mbd=2:mv0: TRELL:V4MV:CBP:LAST_PRED=3:DIA=4:CMP=6:VB_STRATEGY=1-VF scale=512:-3-ofps 12-srate 22050 ", 200));
P.standardinput.writeline ("exit");
Stroutput = P.standardoutput.readtoend ();
Console.WriteLine (Stroutput);
p.WaitForExit ();
P.close ();
Remember to import at the same time: using System.Diagnostics; namespaces. Good luck
Also the heart of the Good XI, although nine died of its not regret. The night is listening to the wind blowing rain, iron horse ice dream come. Coveting is better than to retreat and netting. Drunken lying on the battlefield June Mo Smile, ancient battle several people back!
C # operations. exe files