C# 在C中执行时,如何使用cmd输出将driverquery重定向到文件#
我在我的程序中使用了下面的代码,并且没有生成输出文件。你知道我在这种情况下会做错什么吗C# 在C中执行时,如何使用cmd输出将driverquery重定向到文件#,c#,C#,我在我的程序中使用了下面的代码,并且没有生成输出文件。你知道我在这种情况下会做错什么吗 using (StreamWriter fileWriter = new StreamWriter(tempDirectory+@"\drivertable.txt")) { using (Process driverQuery = new Process()) { if (File.Exists(Environm
using (StreamWriter fileWriter = new StreamWriter(tempDirectory+@"\drivertable.txt"))
{
using (Process driverQuery = new Process())
{
if (File.Exists(Environment.SystemDirectory + @"\driverquery.exe"))
{
driverQuery.StartInfo.FileName = "driverquery.exe";
driverQuery.StartInfo.Arguments = @"/FO table /v >> C:\text.txt";
Console.WriteLine(driverQuery.StartInfo.Arguments);
driverQuery.StartInfo.RedirectStandardOutput = false;
driverQuery.StartInfo.UseShellExecute = true;
driverQuery.Start();
//fileWriter.WriteLine(driverQuery.StandardOutput.ReadToEnd());
driverQuery.WaitForExit();
fileWriter.Close();
}
else
{
Console.WriteLine("Driverquery.exe not found in system");
}
}
}
>
给了我执行的问题。我知道我也可以通过StreamWriter实现这一点,但这似乎是一个更好的选择
谢谢 根据@jdweng的评论,这似乎是不可能的。'>>“不是命令参数。它是标准输出。因此您需要使RedirectStandardOutput=true。然后在代码中您需要捕获标准输出并保存到c#代码中的c:\text.txt。因此,换句话说,我不能使用“>>“C#中的指令,就像我在CMD中使用的一样?不。参数和标准输出是两个独立的对象。参数将不接受标准输出作为项。