C# 进程重定向标准输出详细性问题

C# 进程重定向标准输出详细性问题,c#,python,redirect,output,minecraft,C#,Python,Redirect,Output,Minecraft,我在从C#中的process StandardOutput读取数据时遇到问题。以下是我所拥有的: var hdd = new System.Diagnostics.Process(); hdd.StartInfo.FileName = "C:\\Program Files\\Java\\jre7\\bin\\java.exe"; hdd.StartInfo.Arguments = "-jar minecraft.jar"; hdd.StartInfo.RedirectStandardOutput

我在从C#中的process StandardOutput读取数据时遇到问题。以下是我所拥有的:

var hdd = new System.Diagnostics.Process();
hdd.StartInfo.FileName = "C:\\Program Files\\Java\\jre7\\bin\\java.exe";
hdd.StartInfo.Arguments = "-jar minecraft.jar";
hdd.StartInfo.RedirectStandardOutput = true;
hdd.StartInfo.UseShellExecute = false;
hdd.Start();
while (!hdd.StandardOutput.EndOfStream)
{
    string data = hdd.StandardOutput.ReadLine();
    Console.WriteLine(">> " + data);
}
这里我有第二个代码,是用Python编写的:

cmd = '"C:\\Program Files\\Java\\jre7\\bin\\java.exe" -jar minecraft.jar'
import subprocess
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
while True:
    line = p.stdout.readline()
    print '>> ', line.strip()
    if line == '' and p.poll() != None:
        break
问题是,这两个代码都可以工作,但在python中,脚本打印的信息是C#的两倍

C#输出:

Python的输出:

>>  229 recipes
>>  27 achievements
2013-05-07 18:57:12 [CLIENT] [INFO] LWJGL Version: 2.4.2
>>
>>  Starting up SoundSystem...
>>  Initializing LWJGL OpenAL
>>  (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.or
g)
>>  OpenAL initialized.
>>
2013-05-07 18:57:14 [CLIENT] [INFO] Found animation info for: textures/blocks/lava_flow.txt
2013-05-07 18:57:14 [CLIENT] [INFO] Found animation info for: textures/blocks/water_flow.txt
2013-05-07 18:57:14 [CLIENT] [INFO] Found animation info for: textures/blocks/fire_0.txt
7 more lines similar to last 3 above
所以我们可以清楚地看到,C#中缺少一些信息。具体来说,pythons输出中不带“>>”的行。
有没有办法,我可以用C#?

捕捉那些缺少的行,我想(猜测)你也应该设置
RedirectStandardError=true
;这些附加信息似乎正在传递到标准错误。您可以使用
ErrorDataReceived
来处理这些行。

python捕获的是调试输出吗?如果在运行C#程序的同时启动并保持其运行,您是否会在DbgView窗口中看到类似的内容?@Matthew Watson-不知何故,我无法获得任何实际输出。上面写着[4516]FMAPO:Debug函数是禁用的(DbgView以管理员的身份运行,不管我是手动调试还是运行应用程序)啊,我简直不敢相信它这么简单:(完成并工作了,它确实传递给了StandardError。谢谢!我很高兴它能帮上忙;:)
>>  229 recipes
>>  27 achievements
2013-05-07 18:57:12 [CLIENT] [INFO] LWJGL Version: 2.4.2
>>
>>  Starting up SoundSystem...
>>  Initializing LWJGL OpenAL
>>  (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.or
g)
>>  OpenAL initialized.
>>
2013-05-07 18:57:14 [CLIENT] [INFO] Found animation info for: textures/blocks/lava_flow.txt
2013-05-07 18:57:14 [CLIENT] [INFO] Found animation info for: textures/blocks/water_flow.txt
2013-05-07 18:57:14 [CLIENT] [INFO] Found animation info for: textures/blocks/fire_0.txt
7 more lines similar to last 3 above