Forum posts for Defrag.exe

C# How to Get Output from CMD (Command = “Defrag c: /U”) Before Proccess Ends.

I'm calling Defrag.exe from my c# application. I want to get output of defragmentation proccess when it's updated.

I want this output(in red rectangle) to be printed in my application.(When 11% progress percentage updated it should also be printed.) :



I'm using this code:

Process selectedProc = new Process();
selectedProc.StartInfo.UseShellExecute = false;
selectedProc.StartInfo.RedirectStandardOutput = true;
selectedProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
selectedProc.StartInfo.CreateNoWindow = true;

selectedProc.OutputDataReceived += (sender, e) =>
{
Debug.WriteLine(e.Data);
};

selectedProc.StartInfo.WorkingDirectory = System.IO.Path.GetPathRoot(Environment.SystemDirectory);
selectedProc.StartInfo.FileName = System.IO.Path.Combine(Environment.SystemDirectory, 'defrag.exe');
selectedProc.StartInfo.Arguments = 'C: /U';
selectedProc.Start();
selectedProc.BeginOutputReadLine();


After sometime i'm closing process with this code:

selectedProc.Kill();


Between process.Start() and process.Kill() i'm not seeing any output printed on debug section in Visual Studio. Not even after defrag process ended. Where is the problem ?

View complete forum thread with replies

Other posts related to Defrag.exe

See Related Forum Messages: Follow the Links Below to View Complete Thread

Can't call defrag from perl script on Windows 2008
C# run defrag.exe remotely
Real Time CMD Output on Windows Defrag.exe
Exitcode 6 using PsExec in Windows Service
Schedule using “at” CMD in LOOP
Process.Start in WindowsSystem32 folder
Batch File Creating Text File With Date
what the best and simplest way to find out whether a volume need defrag?
How do I create a batch script that creates a task for a specific user in the Active Directory?
C# How to Get Output from CMD (Command = “Defrag c: /U”) Before Proccess Ends.

What is the carbon footprint of your coffee?

Is it low? Is it high? Can this things really kill the planet Earth? Maybe the answer will surprise you. Maybe not.