没有给外部批处理脚本C#正确的输出
问题描述:
我需要的程序给批处理脚本的输出,而且目前它只是打印没有给外部批处理脚本C#正确的输出
System.IO.StreamReader
,它应该是印刷无论批处理脚本说
这是唯一有开始一个新的进程做了一部分,就像文件路径的变量声明和脚本本身运行,但并没有显示正确的输出
Process Uninstaller = new Process();
Uninstaller.StartInfo.FileName = Path.Combine(uninstalldirectory, BatchProcessFileName);
Uninstaller.StartInfo.UseShellExecute = false;
Uninstaller.StartInfo.CreateNoWindow = true;
Uninstaller.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Uninstaller.StartInfo.RedirectStandardOutput = true;
Uninstaller.Start();
StreamReader ReadUninstallerOutput = Uninstaller.StandardOutput;
Uninstaller.Close();
string OutputEnd = ReadUninstallerOutput.ReadToEnd();
Console.WriteLine(ReadUninstallerOutput);
ReadUninstallerOutput.Close();
Console.WriteLine("Uninstallation Successful");
答
更换
Console.WriteLine(ReadUninstallerOutput);
与
Console.WriteLine(OutputEnd);
答
这是因为您的控制台编写了ReadUninstallerOutput
,它是一个对象,而不是具有所需数据的字符串,并且所有方法都在调用该类型的ToString
方法。从你的代码来看,你会想取代:
Console.WriteLine(ReadUninstallerOutput);
有:
Console.WriteLine(OutputEnd);
+0
双方你这样做是正确,谢谢 – 2009-11-17 02:09:37
+0
+1使分数公平;-) – Gonzalo 2009-11-17 02:11:53
你们都说得对,谢谢 – 2009-11-17 02:10:11