c# - 为 ProcessStartInfo 传递参数时出错

标签 c#

<分区>

在下面的 C# 代码中,我遇到了错误,

ProcessStartInfo psi = new ProcessStartInfo("logman.exe")
            {
                RedirectStandardOutput = true,
                Arguments = "FabricTraces | findstr Root",
                WindowStyle = ProcessWindowStyle.Hidden,
                UseShellExecute = false
            };
            Process proc = Process.Start(psi); ;
            StreamReader myOutput = proc.StandardOutput;
            proc.WaitForExit(20000);
            if (proc.HasExited)
            {
                Console.WriteLine( myOutput.ReadToEnd());
            }

错误,

Argument '|' is unknown.
Argument 'findstr' is unknown.
Argument 'Root' is unknown.

我需要传递以下参数,该怎么做?感谢您的回答。

FabricTraces | findstr Root

控制台输出,

C:>logman.exe findstr根目录 根路径:C:\ProgramData\Windows Fabric\Fabric\log\Traces\

C:>

最佳答案

ProcessStartInfo 接受引号内带有空格的参数并将它们解释为多个参数。因此您应该用双引号将其括起来。 (据我了解,您应该将一个参数传递给流程)

        startInfo.Arguments = "\"FabricTraces | findstr Root\"";

现在它应该被视为一个参数而不是 3 个空格分隔的参数。

关于c# - 为 ProcessStartInfo 传递参数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47390606/

相关文章:

c# - 如何获取和设置当前运行空间中的变量? (基于 cmdlet 的模块)

c# - 将窗口附加到外部进程

c# - Xamarin PCL Android 应用程序在 Release模式下突然崩溃

c# - 没有映射到数据操作中使用的列 'CleaningEmployees.Id' 的属性

c# - 为什么我不能在 Visual Studio 2015 中创建共享项目?

c# - 将数据表中选定的列绑定(bind)到数据网格中

c# - .NET 中的正则表达式是如何实现的?

c# - Float/Float = 奇怪的结果

c# - 在 WP7 的隔离存储中存储类对象

c# - 使用 Postman 登录 Angular ASP.NET CORE 应用程序