这是关于我想用来获取Windows更新信息的一行,这是wmic的一部分.
我的代码看起来像这样:
Process p = new Process();
string arguments = "qfe list full /format:htable > "+ path;
ProcessStartInfo procStartInfo = new ProcessStartInfo("wmic", arguments);
procStartInfo.CreateNoWindow = true;
procStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
procStartInfo.UseShellExecute = false;
p.StartInfo = procStartInfo;
p.Start();
Run Code Online (Sandbox Code Playgroud)
而path是转储文件的有效位置,当然是以hotfixlog.htm结尾.
问题是,根本没有任何事情发生.但是,当我从arguments-variable中获取最终产品,并将其手动粘贴到带有'wmic <variablecontent>'的cmd时,它的工作完全正常,我最终得到了我期望的.htm.
创建的行看起来像这样:
"qfe list full/format:htable> C:\ Users\...\WindowsHotfixes.htm"
我需要更改什么才能使其从代码中运行?我期待反斜杠引起问题,但是当手动输入线时他们没有.
您的代码将无法工作,因为重定向operator(>)不是任何应用程序可用的操作系统的元素,而是运算符cmd.exe.它在命令行中工作,因为cmd它正在处理它,但wmic不知道如何处理它.
如果您的命令行类似,您可以使用重定向
cmd /c"wmic qfe list full /format:htable > x:\somewhere\file.htm"
Run Code Online (Sandbox Code Playgroud)
或者您可以删除重定向并指示wmic您希望将数据保存在文件中
wmic /output:"x:\somewhere\file.htm" qfe list full /format:htable
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
76 次 |
| 最近记录: |