为什么此代码没有从外部命令接收完整的输出? [英] Why does this code not receive the complete output from an external command?

查看:168
本文介绍了为什么此代码没有从外部命令接收完整的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个工具,以便能够在特定的驱动器上找到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中的卷是数据卷序列号为7C64-9650

Volume in drive D is Data Volume Serial Number is 7C64-9650

预期结果:


驱动器D中的卷是数据卷序列号为7C64-9650

Volume in drive D is Data Volume Serial Number is 7C64-9650

目录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));

这篇关于为什么此代码没有从外部命令接收完整的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆