Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

		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

i'm not lazy i'm just resting before i get tired.
Posted

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");

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.

Posted

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

i'm not lazy i'm just resting before i get tired.
Posted

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?

i'm not lazy i'm just resting before i get tired.
Posted

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

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...