使用命令提示符帮助 .ReadToEnd()
嘿,我正在尝试使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么要使用cmd.exe?命令 piso.exe 将退出,但 cmd.exe 不会退出。 ReadToEnd()会一直等待程序cmd.exe退出&不会回来。更好的方法是直接调用 piso.exe 进行安装,在您的情况下将是:
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: