没有给出外部批处理脚本 C# 的正确输出

发布于 2024-08-11 00:47:07 字数 803 浏览 5 评论 0原文

我需要程序提供批处理脚本的输出,目前它只是打印

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十二 2024-08-18 00:47:07

这是因为您让控制台写入 ReadUninstallerOutput,它是一个对象,而不是包含所需数据的字符串,并且所有方法所做的就是调用 ToString该类型的方法。从您的代码来看,您需要将: 替换

Console.WriteLine(ReadUninstallerOutput);

为:

Console.WriteLine(OutputEnd);

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 the ToString method on that type. Judging from your code, you would want to replace:

Console.WriteLine(ReadUninstallerOutput);

with:

Console.WriteLine(OutputEnd);
墨洒年华 2024-08-18 00:47:07

替换

Console.WriteLine(ReadUninstallerOutput);

Console.WriteLine(OutputEnd);

Replace

Console.WriteLine(ReadUninstallerOutput);

with

Console.WriteLine(OutputEnd);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文