Uploaded image for project: 'Modules'
  1. Modules
  2. MODULES-3943

PowerShell - Ensure direct writes to stdout / stderr streams are redirected and captured

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Normal
    • Resolution: Won't Do
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: powershell
    • Labels:
      None
    • Template:
    • Acceptance Criteria:
      • Output that currently comes through via the actual stderr and stdout streams should instead be propagated over the bi-directional pipe used to communicate between PowerShell and Ruby
    • Team:
      Modules

      Description

      It may be possible with native windows APIs (or with a native windows binary) to write to stdout / stderr outside of the redirected [Console]::Out and [Console]::Error that the current PowerShell custom host captures.

      While those streams are drained / collected while executing commands against the PowerShell instance, the behavior there can be non-deterministic, so it would be desirable to have more control if possible.

      Note that:

      • It's unclear if this really matters to users
      • It's unclear if there are any real-world cases where this is a problem
      • Proposed solutions may have Windows-only solutions, rendering them unusable in a cross-platform environment

      A solution for redirecting stdout + stderr in a Windows service exists that uses the SetStdHandle Windows API call. Though there are some circumstances where that might not work.

      It's uncertain if FlushFileBuffers needs to be called at any point. Chocolatey uses the GetStdHandle API when it deals with console behavior.

      P/Invoke defs for StdHandle APIs:

      [DllImport("kernel32.dll", SetLastError = true)]
      internal static extern IntPtr GetStdHandle(int nStdHandle);
       
       
      [DllImport("Kernel32.dll", SetLastError = true)]
      public static extern int SetStdHandle(int device, IntPtr handle);
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ethan Ethan Brown
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Zendesk Support