2

I saw similar posts here on SO, but none seem to have a solution (that works for me). So posting "yet another" in hopes that this one would help identify what's wrong. This is also cross-posted on SysInternals' Forum

I've searched for answers to this problem (and it appears that quite a few people are experiencing it), but none seem to have found a solid solution. So I thought I'll raise the question again as it is quite a pain for us.

I'm trying to use PsExec v2.0 to launch processes on several remote machines (in parallel), wait for those processes to complete, and then examine the error code to make sure all completed successfully. It appears to work fine on some machine, but not all (fails on a coworker and customer environment). Here is the code snippet of how it is used:

        foreach (WorkerServer worker in configSection.WorkerServers)
        {
            Process workerProcess = new Process();
            workerProcess.StartInfo.FileName = PsExecLocation;
            workerProcess.StartInfo.Arguments = BuildPsExecArguments(worker);

            if (configSection.CaptureOutput)
            {
                workerProcess.StartInfo.UseShellExecute = false;
                workerProcess.StartInfo.RedirectStandardError = true;
                workerProcess.StartInfo.RedirectStandardOutput = true;

                workerProcess.OutputDataReceived += new DataReceivedEventHandler(workerProcess_OutputDataReceived);
                workerProcess.ErrorDataReceived += new DataReceivedEventHandler(workerProcess_ErrorDataReceived);
            }

            workerProcess.Start();

            if (configSection.CaptureOutput)
            {
                workerProcess.BeginOutputReadLine();
                workerProcess.BeginErrorReadLine();
            }

            workerProcesses.Add(workerProcess);
        }

        foreach (Process process in workerProcesses)
        {
            process.WaitForExit();
            ......

If above "CaptureOutput" is set and code goes through setting up capturing StdOut and StdErr, then on some machines we observe that remote worker process has exited, but PsExec is still running and not returning the exit code.

Things tried / observed so far:

  • using -i option. When with the option, it doesn't work at all and I get 2250 error. Without it, it does connect and launch process.
  • -d option is not an option b/c I must have the exit code of the remote process.
  • -s didn't help.
  • Not capturing output makes it work (but is an issue as any problems will now be hard to troubleshoot as I can't see psexec output).
    • On a sister project in Java, it is the other way around, not capturing output makes it fail in a similar way.
  • -accepteula is always included.
  • PAExec also seems to have similar problem.
  • Problem seems to be very similar to one described at PsExec hang while being executed from a very simple c# or c++ gui program compiled as "windows application" I observed that PsExec headers appear right away from all children, but status lines about what it's doing and launching and result appear to come only one at a time - meaning until first child is done, second child's status lines do not come in until after first one completes. Not sure if this is related to the issue or not.

Any help would be much appreciated.

Community
  • 1
  • 1
LB2
  • 4,802
  • 19
  • 35

1 Answers1

0

I had lots of problems with Git command line locking up like this, so I wrote a little library to do the process launching:

This uses Windows pipes for std(in|out|err), and does the interop in a different way to System.Diagnostic.Process.

Iain Ballard
  • 4,433
  • 34
  • 39