c # Winform call exe executable file

c # is a windows desktop gadget write good things, but there was a time when we need to call other exe file in winform program, then how to achieve it?

If only pull a exe file, reference may be implemented as follows:

string exefile = " xxx.exe " ;
 IF (the File.Exists (exefile)) { 
    Process Process = new new Process (); 
   // the params, a plurality of parameters separated by a space of type string parameter, if a parameter is null, you can pass "" the ProcessStartInfo the StartInfo
= new new the ProcessStartInfo (exefile, the params); process.StartInfo = the StartInfo; Process.Start (); }

If you do not want pop-up system dos interface, you can refer to the following ways:

string exefile = "xxx.exe";
if (File.Exists(exefile)) {
    Process process = new Process();
    ProcessStartInfo startInfo = new ProcessStartInfo(exefile, path);
    startInfo.UseShellExecute = false;
    startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true; process.StartInfo
= startInfo; process.Start(); process.WaitForExit(2000); string output = process.StandardOutput.ReadToEnd(); rtb_analyze.Text = output; process.Close(); }

Of course, there are asynchronous mode:

public void exec(string exePath, string parameters)
{
    Process process = new System.Diagnostics.Process();
    process.StartInfo.FileName = exePath;
    process.StartInfo.Arguments = parameters;
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.CreateNoWindow = true;
    process.StartInfo.RedirectStandardOutput = true;
    process.Start();
    process.BeginOutputReadLine();
    process.OutputDataReceived += new  DataReceivedEventHandler(processOutputDataReceived);
}

 

 

Guess you like

Origin www.cnblogs.com/xsbx/p/winform.html