这个问题与提出的问题不同:
请不将其视为副本,因为它不是。
我发现自己无法点击在我的应用程序之外创建的stderr
和stdout
个流程。
targetProcessList
的类型为List<System.Diagnostics.Process>
。
以下代码
foreach (var proc in targetProcessList)
{
proc.StandardError.ReadToEndAsync().ContinueWith(t => Console.WriteLine(t.Result));
proc.StandardOutput.ReadToEndAsync().ContinueWith(t => Console.WriteLine(t.Result));
}
导致InvalidOperationException
(可能是因为没有为此类用法配置进程):
[c:\ HRIS.Web] dotnet run : User profile is available. Using ' \AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
[c:\ HRIS.Web] dotnet run :
[c:\ HRIS.SPA] npm run start-prodish-for-e2e ||| [12044] cmd
[c:\ HRIS.SPA] npm run start-prodish-for-e2e ||| [11080] conhost
System.InvalidOperationException: StandardError has not been redirected.
at System.Diagnostics.Process.get_StandardError()
at RunE2E.Program.StartProcessViaCmd(String command, String arguments, String workingDirectory)
at RunE2E.Program.Main(String[] args)
System.NullReferenceException: Object reference not set to an instance of an object.
at RunE2E.Program.Main(String[] args)
所以,我试图像这样动态启用重定向:
foreach (var proc in targetProcessList)
{
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StandardError.ReadToEndAsync().ContinueWith(t => Console.WriteLine(t.Result));
proc.StandardOutput.ReadToEndAsync().ContinueWith(t => Console.WriteLine(t.Result));
}
但在运行时仍然受到打击
[c:\ \HRIS.Web] dotnet run : User profile is available. Using ' \AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
[c:\ \HRIS.Web] dotnet run :
[c:\ \HRIS.SPA] npm run start-prodish-for-e2e ||| [14952] cmd
[c:\ \HRIS.SPA] npm run start-prodish-for-e2e ||| [10784] conhost
System.InvalidOperationException: Process was not started by this object, so requested information cannot be determined.
at System.Diagnostics.Process.get_StartInfo()
at RunE2E.Program.StartProcessViaCmd(String command, String arguments, String workingDirectory)
at RunE2E.Program.Main(String[] args)
System.NullReferenceException: Object reference not set to an instance of an object.
at RunE2E.Program.Main(String[] args)
有办法解决这个问题吗?