views:

46

answers:

1

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";
A: 

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);
Yogesh
Thanks for the reply, I was using cmd.exe to run several commands and verify they were executed correctly, I will try to break it up using piso.exe and get back to you : )
Scott