问题描述
我正在使用一个工具,以便能够在特定的驱动器上找到PST。这个代码正在采取项目路径,因为它是为了测试目的。
I am working on a tool to be able to find a PST on a specific drive. This code is taking the project path just because it's for testing purpose.
我的问题是,当我尝试获取shell命令的执行输出在外部命令处理器,我只有两个第一行:
My problem is that when I try to get the output of the execution of a shell command in an external command processor, I only got the 2 first lines:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/C dir /s *.pst";
p.Start();
string output = p.StandardOutput.ReadToEnd();
MessageBox.Show(output);
p.WaitForExit();
我的结果:
预期结果:
目录D:\PATH 13/12/2012 01:49 PM 1,014,047,744
Archives.pst 4文件1,355,919,360字节
Directory of D:\PATH 13/12/2012 01:49 PM 1,014,047,744 Archives.pst 4 File(s) 1,355,919,360 bytes
没有错误消息
推荐答案
也许会更容易吗?您当前的代码是不值得的麻烦。
Perhaps another way to skin the cat would be easier? Your current code is not worth the trouble.
// .Net 2.0
string[] psts = Directory.GetFiles(".", "*.pst", SearchOption.AllDirectories);
// .Net 4.0+
var psts = Directory.EnumerateFiles(".", "*.pst", SearchOption.AllDirectories);
使用方式如下:
MessageBox.Show(String.Join(", ", psts));
这篇关于为什么此代码没有从外部命令接收完整的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!