bpayne111 Posted September 3, 2004 Posted September 3, 2004 public void FormatDisk() { string temp=""; System.Diagnostics.ProcessStartInfo ps = new System.Diagnostics.ProcessStartInfo(); ps.FileName="c:\\windows\\system32\\format.com"; ps.Arguments="a: "; ps.CreateNoWindow = true; ps.RedirectStandardOutput=true; ps.RedirectStandardInput=true; //ps.RedirectStandardError = true; ps.UseShellExecute=false; System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo=ps; p.Start(); StreamWriter sIn = p.StandardInput; // try { //sIn.Write(System.Environment.NewLine); while(p.StandardOutput.Peek() != -1) { temp = p.StandardOutput.ReadLine(); //read stream Debug.WriteLine(temp); } sIn.Write(System.Environment.NewLine); while(p.StandardOutput.Peek() != -1) { temp = p.StandardOutput.ReadLine(); //read stream Debug.WriteLine(temp); } } catch(Exception err) { Debug.WriteLine(err.Message.ToString()); } p.Close(); Debug.WriteLine("process closed"); } when this code is run the output window only shows the following: Insert new disk for drive A: process closed any ideas on what's going on here? i'm pretty stuck at this point because i have no trouble with .exe's but .com seems to act funny thanks, brandon Quote i'm not lazy i'm just resting before i get tired.
Joe Mamma Posted September 3, 2004 Posted September 3, 2004 I havent looked very closely at exactly what you are trying to do here, but I gather you are just wanting to kick off the format command and wait for it to finish and then write 'process closed' where is your loop checoking the Process.HasExited value? while ( !p.HasExited) try { } catch(Exception err) { Console.WriteLine(err.Message.ToString()); } p.Close(); Debug.WriteLine("process closed"); Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
bpayne111 Posted September 3, 2004 Author Posted September 3, 2004 while ( !p.HasExited) QUOTE] funny enough i get this error now The following exception occurred: System.InvalidOperationException: No process is associated with this object. the loop was inserted after the process was initialized hmm thanks though brandon Quote i'm not lazy i'm just resting before i get tired.
bpayne111 Posted September 5, 2004 Author Posted September 5, 2004 I still get the same results as before... except for now the process is never closed. is this because i'm using a .com instead of a .exe? Quote i'm not lazy i'm just resting before i get tired.
Joe Mamma Posted September 6, 2004 Posted September 6, 2004 the command line you want to execute is - cmd /c format a: cmd is the process, /c format a: is the argument string, ala - ProcessStartInfo pi new ProcessStartInfo("cmd.exe", "/c format a:"); Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
bpayne111 Posted September 6, 2004 Author Posted September 6, 2004 why /c? i'm gonna try it now thanks, brandon Quote i'm not lazy i'm just resting before i get tired.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.