C# call Exe
==========================================================
class Program
{
static void DisplayBitArrAY()
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = @"D:\Program Files (x86)\Tencent\QQ\Bin\QQ.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.Arguments = "你好, 北京 欢迎你!";
{
static void DisplayBitArrAY()
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = @"D:\Program Files (x86)\Tencent\QQ\Bin\QQ.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.Arguments = "你好, 北京 欢迎你!";
process.Start();//process.Close();
process.WaitForExit();// if (process.HasExited)
Console.WriteLine("complete : {0}", process.ExitCode);
}
static void Main(string[] args)
{
DisplayBitArrAY();
}
}
Console.WriteLine("complete : {0}", process.ExitCode);
}
static void Main(string[] args)
{
DisplayBitArrAY();
}
}
==============================================================
When writing a program, it is often used to call an executable program. This article will briefly introduce the method of C# calling exe. In C#, process operations are performed through the Process class. The Process class is in the System.Diagnostics package.
Example one
using System.Diagnostics;
Process p = Process.Start("notepad.exe");
p.WaitForExit();//Key, wait for the external program to exit before proceeding
p.WaitForExit();//Key, wait for the external program to exit before proceeding
The Notepad program can be called by the above code. Note that if you are not calling the system program, you need to enter the full path.
Example two
When the cmd program needs to be called, using the above calling method will pop up annoying black windows. If you want to eliminate it, you need to make more detailed settings.
The StartInfo property of the Process class contains some process startup information, of which several are more important
FileName executable program file name
Arguments program parameters, entered in the form of a string.
CreateNoWindow does not need to create a window
UseShellExecute whether to call the program by the system shell
CreateNoWindow does not need to create a window
UseShellExecute whether to call the program by the system shell
Through the above parameters, the annoying black screen can disappear
System.Diagnostics.Process exep = new System.Diagnostics.Process();
exep.StartInfo.FileName = binStr;
exep.StartInfo.Arguments = cmdStr;
exep.StartInfo.CreateNoWindow = true;
exep.StartInfo.UseShellExecute = false;
exep. Start();
exep.WaitForExit();//Key, wait for the external program to exit before proceeding
exep.StartInfo.FileName = binStr;
exep.StartInfo.Arguments = cmdStr;
exep.StartInfo.CreateNoWindow = true;
exep.StartInfo.UseShellExecute = false;
exep. Start();
exep.WaitForExit();//Key, wait for the external program to exit before proceeding
or
System.Diagnostics.Process exep = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = binStr;
startInfo.Arguments = cmdStr;
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
exep.Start(startInfo);
exep.WaitForExit();//Key, wait for the external program to exit before proceeding