使用命令提示符帮助 .ReadToEnd()

发布于 2024-09-25 00:53:42 字数 1833 浏览 1 评论 0原文

嘿,我正在尝试使用PowerISO的命令行程序piso。

我正在使用 C# 打开一个进程并输入命令来挂载 cd/dvd。这工作正常,每次都会安装 cd/dvd。

问题是 .ReadToEnd() 不会停止读取并且程序挂在此处。似乎命令提示符的响应应该是

PowerISO Version 4.5 Copyright(C) 2004-2009 PowerISO Computing, Inc Type piso -? for help

Mount successfully

“但是我只是到达:”

PowerISO Version 4.5 Copyright(C) 2004-2009 PowerISO Computing, Inc Type piso -? for help

并且程序将继续永远读取,永远不会成功安装“Mount”输出。

这是我的 C# 代码:

String output = "";
System.Diagnostics.Process cmd = new System.Diagnostics.Process();
cmd.StartInfo.WorkingDirectory = @"C:\";               //@"

cmd.StartInfo.FileName = Path.Combine(Environment.SystemDirectory, "cmd.exe");
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.RedirectStandardError = false;
cmd.Start();

cmd.StandardInput.WriteLine(MountPrgLoc + " " + 
                                                MountPrgCmd_Mount + " " +
                                                location + " " +
                                                drive);
StreamReader sr = cmd.StandardOutput;
output = sr.ReadToEnd() ;
MessageBox.Show(output);

提前感谢您的帮助 -斯科特

------------------编辑----------------- 更多信息:

/* DVD Attributes */
String name = "My Movie Title";
String location = "\"" + @"C:\Users\Razor\Videos\iso\Movie.iso" + "\"";
String drive= "H:";
String format = ".iso";

/* Special Attributes */
String PlayPrg = "Windows Media Center";
String PlayPrgLoc = @"%windir%\ehome\";       //@"
String MountPrg = "PowerISO";
String MountPrgLoc = "\"" + @"C:\Program Files (x86)\PowerISO\piso.exe" + "\"";    //@"
String MountPrgCmd_Mount = "mount";
String MountPrgCmd_Unmount = "unmount";

Hey, I am trying to use PowerISO's command line program piso.

I am using C# to open a process and enter the command to mount a cd/dvd. This is working fine and the cd/dvd gets mounted every time.

The trouble is that .ReadToEnd() will not stop reading and the program hangs here. It seems as though the response from the command prompt should be

PowerISO Version 4.5 Copyright(C) 2004-2009 PowerISO Computing, Inc Type piso -? for help

Mount successfully

However I am only getting to :

PowerISO Version 4.5 Copyright(C) 2004-2009 PowerISO Computing, Inc Type piso -? for help

and the program will continue to read forever, never getting the Mount successfully output.

Here is my C# code:

String output = "";
System.Diagnostics.Process cmd = new System.Diagnostics.Process();
cmd.StartInfo.WorkingDirectory = @"C:\";               //@"

cmd.StartInfo.FileName = Path.Combine(Environment.SystemDirectory, "cmd.exe");
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.RedirectStandardError = false;
cmd.Start();

cmd.StandardInput.WriteLine(MountPrgLoc + " " + 
                                                MountPrgCmd_Mount + " " +
                                                location + " " +
                                                drive);
StreamReader sr = cmd.StandardOutput;
output = sr.ReadToEnd() ;
MessageBox.Show(output);

Thanks in advance for any help
-Scott

------------------Edit -----------------
More info:

/* DVD Attributes */
String name = "My Movie Title";
String location = "\"" + @"C:\Users\Razor\Videos\iso\Movie.iso" + "\"";
String drive= "H:";
String format = ".iso";

/* Special Attributes */
String PlayPrg = "Windows Media Center";
String PlayPrgLoc = @"%windir%\ehome\";       //@"
String MountPrg = "PowerISO";
String MountPrgLoc = "\"" + @"C:\Program Files (x86)\PowerISO\piso.exe" + "\"";    //@"
String MountPrgCmd_Mount = "mount";
String MountPrgCmd_Unmount = "unmount";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

别在捏我脸啦 2024-10-02 00:53:42

为什么要使用cmd.exe?命令 piso.exe 将退出,但 cmd.exe 不会退出。 ReadToEnd()会一直等待程序cmd.exe退出&不会回来。更好的方法是直接调用 piso.exe 进行安装,在您的情况下将是:

String output = "";
System.Diagnostics.Process cmd = new System.Diagnostics.Process();
cmd.StartInfo.WorkingDirectory = @"C:\Program Files (x86)\PowerISO";

cmd.StartInfo.FileName = "piso.exe";
cmd.StartInfo.Arguments = MountPrgCmd_Mount + " " + location + " " + drive;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.Start();

StreamReader sr = cmd.StandardOutput;
output = sr.ReadToEnd();
cmd.WaitForExit();
MessageBox.Show(output);

Why do you want to use cmd.exe? The command piso.exe will exit, but cmd.exe will not. ReadToEnd() will keep waiting for the program cmd.exe to exit & will not return. A better way will be to directly call piso.exe to do the mounting, which in your case will be:

String output = "";
System.Diagnostics.Process cmd = new System.Diagnostics.Process();
cmd.StartInfo.WorkingDirectory = @"C:\Program Files (x86)\PowerISO";

cmd.StartInfo.FileName = "piso.exe";
cmd.StartInfo.Arguments = MountPrgCmd_Mount + " " + location + " " + drive;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.Start();

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