【发布时间】:2020-12-18 22:21:52
【问题描述】:
我有启动进程的 C# 自动化代码
var proc1 = new ProcessStartInfo();
string anyCommand = " adb logcat - v threadtime emulator-5554 > logcat.log";
proc1.UseShellExecute = true;
proc1.WorkingDirectory = outputDirectory;
proc1.FileName = @"C:\Windows\System32\cmd.exe";
proc1.Verb = "runas";
proc1.Arguments = "/c " + anyCommand;
proc1.WindowStyle = ProcessWindowStyle.Hidden;
Process p = new Process();
p.StartInfo = proc1;
p.Start();
Console.WriteLine(p.Id);
TestLogger.WriteInformationStep("p.Id: " + p.Id);
经过一些步骤后,我正在尝试读取文件
string text2 = System.IO.File.ReadAllText(element);
但我收到错误消息
System.IO.IOException : 进程无法访问文件 'C:\Users\test\Documents\overview9\bin\Debug\Results\logcat.log' 因为它正在被另一个进程使用。拆除 : HarVE.Log.FailedStepException:有 1 个失败的步骤:测试完成 没有运行完成
我该怎么办?
我试过p.Close();p.Kill();
它们都不适合我。
【问题讨论】:
标签: c# powershell automation process