1. process 是一个进程,new proces是创建一个新的进程,
2. 线程是thread,它是操作系统的最小的单位,一个进程可以包含多个线程,线程里面可以执行创建进程操作
3. 32位操作系统只能访问32位的进程,比如一个32位的电脑,执行一个exe,这个exe也必须是32位的,否则会报 Win32Exception
4. Process 的 StandardOutput: 表示它执行进程是的输出流,前提条件:RedirectStandardOutput=true、 UseShellExecute=false
.
using (Process process = new Process())
{
process.StartInfo.FileName = "ipconfig.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
// Synchronously read the standard output of the spawned process.
StreamReader reader = process.StandardOutput;
string output = reader.ReadToEnd();
// Write the redirected output to this application's window.
Console.WriteLine(output);
process.WaitForExit();
}
读取操作包括同步和异步两种,同步读操作直到相关的Process写入StandardOutput流或关闭该流才会完成。
异步读取为StandardOutput输出启用指定的Handler,并立即返回给调用方,在StandardOutput被定向到事件处理程序时,调用方可以执行其他工作
它的参数filename是必传的,可以是一个应用程序,也可以是一个可执行文件,比如一个.sh文件,也可以是一个.doc 文件,它用什么打开取决于它关联的应用程序,比如.doc文件用WPS打开。
ArgumentList | 添加命令不需要转移,不需要预留空格,比如 { "/c", "dir", @"C:\Program Files\dotnet" } |
Arguments | 需要完整的参数格式:"/c dir \"C:\\Program Files\\dotnet\"",需要预留空格 |
CreateNoWindow | 是否开启一个新的窗口 |
Environment | 获取应用于此进程及其子进程的环境变量,它是只读的,但是可以更改获取它的变量,更改完之后,UseShellExecute 需要设置为false myProcess.StartInfo.Environment.Add("TempPath", "C:\\Temp") |
FileName | Gets or sets the application or document to start. |
UseShellExecute | 该值指示是否使用操作系统shell启动进程。 Setting this property to 指的是graphical shell(类似于Windows shell),而不是命令shell(例如bash或sh),并允许用户启动图形应用程序或打开文档。 |
WorkingDirectory | 当 UseShellExecute = |