没有给出外部批处理脚本 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");
I need the program to give the output of the batch script, and at the moment it's just printing
System.IO.StreamReader
and it should be printing whatever the batch script says
This is only the part that has to do with starting a new process, the variables like the path to the file are declared and the script itself runs but doesn't show proper output
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");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为您让控制台写入
ReadUninstallerOutput
,它是一个对象,而不是包含所需数据的字符串,并且所有方法所做的就是调用ToString
该类型的方法。从您的代码来看,您需要将: 替换为:
That's because you're having the Console write
ReadUninstallerOutput
, which is an object, not the string that has the data you want, and all the method is doing is calling theToString
method on that type. Judging from your code, you would want to replace:with:
替换
为
Replace
with