0

I am running sDelete64.exe inside a WinForms application. I redirect it's output to a textbox. However, only the first line of the output is redirected. What sDelete displays if you run it normally is

sDelete is set for 1 pass.
Zeroing free space on C:\: 0%

When I redirect it I only get the first line. If I redirect a command like dir, no problem I get everything back.

    private bool ExecuteCmd(string command)
    {
        var startInfo = new ProcessStartInfo("cmd.exe")
        {
            RedirectStandardInput = true,
            RedirectStandardOutput = true,
            RedirectStandardError = true,
            UseShellExecute = false,
            CreateNoWindow = true,
            Arguments = "/c " + command
        };


        _process = new Process { StartInfo = startInfo };
        Logger.Debug(string.Format("Cmd.exe is Launching command {0}", command));
        _process.Start();

        _process.OutputDataReceived += (o, e) =>
        {
            if (!string.IsNullOrEmpty(e.Data))
            {
                Logger.Debug("Updating loading panel with {0}", e.Data);
                _textBox.Text += e.Data + "\r\n";

            }

        };

        _process.ErrorDataReceived += (o, e) =>
        {
            if (!string.IsNullOrEmpty(e.Data))
            {
                Logger.Debug("Updating loading panel with {0}", e.Data);
                _textBox.Text += e.Data + "\r\n";

            }

        };

        _process.BeginErrorReadLine();

        _process.BeginOutputReadLine();

        _process.WaitForExit();

        return _process.HasExited;

What could cause sDelete's StandardOutput not be captured?

Woot
  • 1,759
  • 1
  • 16
  • 23

1 Answers1

0

Really I found the answer here. Creating a process that will continually read from the StandardOutput Stream and update a StreamWriter.

C# - Realtime console output redirection

Community
  • 1
  • 1
Woot
  • 1,759
  • 1
  • 16
  • 23