Process
p = CreateProcess(
Path
.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System),
"cmd.exe"
), dir);
StringBuilder
result =
new
StringBuilder
();
p.ErrorDataReceived +=
new
DataReceivedEventHandler(
delegate
(
object
sender, DataReceivedEventArgs e)
result.AppendLine(e.Data);
p.OutputDataReceived +=
new
DataReceivedEventHandler(
delegate
(
object
sender, DataReceivedEventArgs e)
ShowNormalInfo(e.Data);
result.AppendLine(e.Data);
p.Start();
p.BeginErrorReadLine();
p.BeginOutputReadLine();
p.StandardInput.WriteLine(
"exit"
);
p.WaitForExit();
p.Close();
p.Dispose();
C#调用执行命令行窗口cmd,及需要交互执行的处理
C#执行外部程序用到的是Process进程类,打开一个进程,可以指定进程的启动信息StartInfo(启动的程序名、输入输出是否重定向、是否显示UI界面、一些必要参数等)...
CompletableFuture的applyToEitherAsync:最快返回输出的线程结果作为下一次任务的输入
applyToEitherAsync和附录1的acceptEitherAsync类似,只是说acceptEitherAsync是对结果的消费,而applyToEitherAsync则是把最快返回的计算输出结果,再利用起来作为下一次线程任务的输入。