Exemple #1
0
        /// <summary>
        /// The mediator will take actions from the StdIn stream and responds to them.
        /// It will replace StdIn,StdOut and StdErr stream with TextWriter.Null. This is
        /// to make sure these streams are totally used by our Mediator.
        /// </summary>
        /// <param name="combineErrOutStream">Redirects remoting errors to the Out stream.</param>
        private StdIOProcessMediator(bool combineErrOutStream) : base(exitProcessOnError: true)
        {
            // Create input stream reader from Console standard input stream.
            // We don't use the provided Console.In TextReader because it can have
            // an incorrect encoding, e.g., Hyper-V Container console where the
            // TextReader has incorrect default console encoding instead of the actual
            // stream encoding.  This way the stream encoding is determined by the
            // stream BOM as needed.
            originalStdIn = new StreamReader(Console.OpenStandardInput(), true);

            // Remoting errors can optionally be written to stdErr or stdOut with
            // special formatting.
            originalStdOut = new OutOfProcessTextWriter(Console.Out);
            if (combineErrOutStream)
            {
                originalStdErr = new FormattedErrorTextWriter(Console.Out);
            }
            else
            {
                originalStdErr = new OutOfProcessTextWriter(Console.Error);
            }

            // Replacing StdIn, StdOut, StdErr with Null so that no other app messes with the
            // original streams.
            Console.SetIn(TextReader.Null);
            Console.SetOut(TextWriter.Null);
            Console.SetError(TextWriter.Null);
        }
Exemple #2
0
        private NamedPipeProcessMediator(
            RemoteSessionNamedPipeServer namedPipeServer) : base(false)
        {
            if (namedPipeServer == null)
            {
                throw new PSArgumentNullException(nameof(namedPipeServer));
            }

            _namedPipeServer = namedPipeServer;

            // Create transport reader/writers from named pipe.
            originalStdIn  = namedPipeServer.TextReader;
            originalStdOut = new OutOfProcessTextWriter(namedPipeServer.TextWriter);
            originalStdErr = new FormattedErrorTextWriter(namedPipeServer.TextWriter);

#if !UNIX
            // Flow impersonation as needed.
            Utils.TryGetWindowsImpersonatedIdentity(out _windowsIdentityToImpersonate);
#endif
        }