WaitForExit () process never ends (cmd openfiles)

this code works fine on my test system (copy of the original Windows-Server 2008 R2)

private string _getNetFiles()
{
    // prepare execution process
    ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe", "/c openfiles /query /Fo list");
    processStartInfo.CreateNoWindow = true;
    processStartInfo.UseShellExecute = false;
    processStartInfo.RedirectStandardError = true;
    processStartInfo.StandardOutputEncoding = System.Text.Encoding.GetEncoding(437);
    processStartInfo.RedirectStandardOutput = true;

    // execute
    Process process = Process.Start(processStartInfo);
    process.WaitForExit();


    // read outputs
    string stdOutput = process.StandardOutput.ReadToEnd();
    string stdError = process.StandardError.ReadToEnd();

    return stdOutput;
}

On the source system: I see the cmd.exe / c openfiles / query / Fo list task in Task-Manger, but this task never ends (process.WaitForExit () never ends). Cmd on the source system: openfiles / query / fo list works fine!

Where could the problem be?

- greeting

edit: I can stop the process using the task manager. The value of stdOutput is correct. Why not finish cmd-taks.

+4
source share
1 answer

All Articles