(
            self, input=None, add_to_history=False, apartment_state=None,
            redirect_shell_error_to_out=False,
            remote_stream_options=RemoteStreamOptions.ADD_INVOCATION_INFO)
Invoke the command asynchronously, use end_invoke to get the output
        collection of return objects.

        :param input: List of inputs to the command, this will be manually
            serialized but can also be a result of runspace_pool.serialize()
        :param add_to_history: Add the commands run to the pool history
        :param apartment_state: Override the RunspacePool apartment state with
            one just for this invocation
        :param redirect_shell_error_to_out: Whether to redirect the global
            error output pipe to the commands error output pipe.
        :param remote_stream_options: Whether to return the invocation info on
            the various steams, see complex_objects.RemoteStreamOptions for the
            values. Will default to returning the invocation info on all
Invoke the command asynchronously, use end_invoke to get the output
        collection of return objects.
Invoke the command asynchronously use end_invoke to get the output collection of return objects .
def begin_invoke(
            self, input=None, add_to_history=False, apartment_state=None,
            redirect_shell_error_to_out=False,
            remote_stream_options=RemoteStreamOptions.ADD_INVOCATION_INFO):
        """
        Invoke the command asynchronously, use end_invoke to get the output
        collection of return objects.

        :param input: List of inputs to the command, this will be manually
            serialized but can also be a result of runspace_pool.serialize()
        :param add_to_history: Add the commands run to the pool history
        :param apartment_state: Override the RunspacePool apartment state with
            one just for this invocation
        :param redirect_shell_error_to_out: Whether to redirect the global
            error output pipe to the commands error output pipe.
        :param remote_stream_options: Whether to return the invocation info on
            the various steams, see complex_objects.RemoteStreamOptions for the
            values. Will default to returning the invocation info on all
        """
        log.info("Beginning remote Pipeline invocation")
        if self.state != PSInvocationState.NOT_STARTED:
            raise InvalidPipelineStateError(
                self.state, PSInvocationState.NOT_STARTED,
                "start a PowerShell pipeline"
            )

        if len(self.commands) == 0:
            raise InvalidPSRPOperation("Cannot invoke PowerShell without any "
                                       "commands being set")

        no_input = input is None or not input
        apartment_state = apartment_state or self.runspace_pool.apartment_state
        host_info = HostInfo(host=self.runspace_pool.host)

        pipeline = Pipeline(
            is_nested=self.is_nested,
            cmds=self.commands,
            history=self.history_string,
            redirect_err_to_out=redirect_shell_error_to_out
        )
        create_pipeline = CreatePipeline(
            no_input, ApartmentState(value=apartment_state),
            RemoteStreamOptions(value=remote_stream_options), add_to_history,
            host_info, pipeline, self.is_nested
        )
        self._invoke(create_pipeline)

        # finally send the input if any was specified
        if input is not None:
            if not isinstance(input, types.GeneratorType):
                def input_gen(i):
                    yield i
                input = input_gen(input)

            log.info("Sending input to remote Pipeline")
            next_input = next(input)
            while next_input is not None:
                if not isinstance(next_input, list):
                    next_input = [next_input]

                input_msgs = [PipelineInput(data=d) for d in next_input]

                try:
                    next_input = next(input)
                except StopIteration:
                    input_msgs.append(EndOfPipelineInput())
                    next_input = None

                fragments = self.runspace_pool._fragmenter.fragment_multiple(
                    input_msgs, self.runspace_pool.id, self.id
                )

                for fragment in fragments:
                    self.runspace_pool.shell.send('stdin', fragment,
                                                  command_id=self._command_id)
def begin_invoke ( self , input = None , add_to_history = False , apartment_state = None , redirect_shell_error_to_out = False , remote_stream_options = RemoteStreamOptions . ADD_INVOCATION_INFO ) : log . info ( "Beginning remote Pipeline invocation" ) if self . state != PSInvocationState . NOT_STARTED : raise InvalidPipelineStateError ( self . state , PSInvocationState . NOT_STARTED , "start a PowerShell pipeline" ) if len ( self . commands ) == 0 : raise InvalidPSRPOperation ( "Cannot invoke PowerShell without any " "commands being set" ) no_input = input is None or not input apartment_state = apartment_state or self . runspace_pool . apartment_state host_info = HostInfo ( host = self . runspace_pool . host ) pipeline = Pipeline ( is_nested = self . is_nested , cmds = self . commands , history = self . history_string , redirect_err_to_out = redirect_shell_error_to_out ) create_pipeline = CreatePipeline ( no_input , ApartmentState ( value = apartment_state ) , RemoteStreamOptions ( value = remote_stream_options ) , add_to_history , host_info , pipeline , self . is_nested ) self . _invoke ( create_pipeline ) # finally send the input if any was specified if input is not None : if not isinstance ( input , types . GeneratorType ) : def input_gen ( i ) : yield i input = input_gen ( input ) log . info ( "Sending input to remote Pipeline" ) next_input = next ( input ) while next_input is not None : if not isinstance ( next_input , list ) : next_input = [ next_input ] input_msgs = [ PipelineInput ( data = d ) for d in next_input ] try : next_input = next ( input ) except StopIteration : input_msgs . append ( EndOfPipelineInput ( ) ) next_input = None fragments = self . runspace_pool . _fragmenter . fragment_multiple ( input_msgs , self . runspace_pool . id , self . id ) for fragment in fragments : self . runspace_pool . shell . send ( 'stdin' , fragment , command_id = self . _command_id )