@@ -614,12 +614,10 @@ def execute_async(
614614
615615 return SshExecuteAsyncResult (chan , _stdin , stderr , stdout )
616616
617- def _exec_command (
617+ def _exec_command ( # type: ignore
618618 self ,
619619 command : str ,
620- interface : paramiko .channel .Channel ,
621- stdout : typing .Optional [paramiko .ChannelFile ],
622- stderr : typing .Optional [paramiko .ChannelFile ],
620+ async_result : SshExecuteAsyncResult ,
623621 timeout : typing .Union [int , float , None ],
624622 verbose : bool = False ,
625623 log_mask_re : typing .Optional [str ] = None ,
@@ -629,12 +627,8 @@ def _exec_command(
629627
630628 :param command: executed command (for logs)
631629 :type command: str
632- :param interface: interface to control execution
633- :type interface: paramiko.channel.Channel
634- :param stdout: source for STDOUT read
635- :type stdout: typing.Optional[paramiko.ChannelFile]
636- :param stderr: source for STDERR read
637- :type stderr: typing.Optional[paramiko.ChannelFile]
630+ :param async_result: execute_async result
631+ :type async_result: SshExecuteAsyncResult
638632 :param timeout: timeout before stop execution with TimeoutError
639633 :type timeout: typing.Union[int, float, None]
640634 :param verbose: produce log.info records for STDOUT/STDERR
@@ -653,10 +647,10 @@ def _exec_command(
653647
654648 def poll_streams () -> None :
655649 """Poll FIFO buffers if data available."""
656- if stdout and interface .recv_ready ():
657- result .read_stdout (src = stdout , log = self .logger , verbose = verbose )
658- if stderr and interface .recv_stderr_ready ():
659- result .read_stderr (src = stderr , log = self .logger , verbose = verbose )
650+ if async_result . stdout and async_result . interface .recv_ready ():
651+ result .read_stdout (src = async_result . stdout , log = self .logger , verbose = verbose )
652+ if async_result . stderr and async_result . interface .recv_stderr_ready ():
653+ result .read_stderr (src = async_result . stderr , log = self .logger , verbose = verbose )
660654
661655 @threaded .threadpooled
662656 def poll_pipes (stop : threading .Event ) -> None :
@@ -666,21 +660,21 @@ def poll_pipes(stop: threading.Event) -> None:
666660 """
667661 while not stop .is_set ():
668662 time .sleep (0.1 )
669- if stdout or stderr :
663+ if async_result . stdout or async_result . stderr :
670664 poll_streams ()
671665
672- if interface .status_event .is_set ():
673- result .read_stdout (src = stdout , log = self .logger , verbose = verbose )
674- result .read_stderr (src = stderr , log = self .logger , verbose = verbose )
675- result .exit_code = interface .exit_status
666+ if async_result . interface .status_event .is_set ():
667+ result .read_stdout (src = async_result . stdout , log = self .logger , verbose = verbose )
668+ result .read_stderr (src = async_result . stderr , log = self .logger , verbose = verbose )
669+ result .exit_code = async_result . interface .exit_status
676670
677671 stop .set ()
678672
679673 # channel.status_event.wait(timeout)
680674 cmd_for_log = self ._mask_command (cmd = command , log_mask_re = log_mask_re )
681675
682676 # Store command with hidden data
683- result = exec_result .ExecResult (cmd = cmd_for_log )
677+ result = exec_result .ExecResult (cmd = cmd_for_log , stdin = kwargs . get ( "stdin" ) )
684678
685679 stop_event = threading .Event ()
686680
@@ -693,11 +687,11 @@ def poll_pipes(stop: threading.Event) -> None:
693687
694688 # Process closed?
695689 if stop_event .is_set ():
696- interface .close ()
690+ async_result . interface .close ()
697691 return result
698692
699693 stop_event .set ()
700- interface .close ()
694+ async_result . interface .close ()
701695 future .cancel ()
702696
703697 wait_err_msg = _log_templates .CMD_WAIT_ERROR .format (result = result , timeout = timeout )
@@ -774,9 +768,15 @@ def execute_through_host(
774768
775769 channel .exec_command (command ) # nosec # Sanitize on caller side
776770
771+ async_result = SshExecuteAsyncResult (interface = channel , stdin = None , stdout = stdout , stderr = stderr )
772+
777773 # noinspection PyDictCreation
778774 result = self ._exec_command (
779- command , channel , stdout , stderr , timeout , verbose = verbose , log_mask_re = kwargs .get ("log_mask_re" , None )
775+ command ,
776+ async_result = async_result ,
777+ timeout = timeout ,
778+ verbose = verbose ,
779+ log_mask_re = kwargs .get ("log_mask_re" , None ),
780780 )
781781
782782 intermediate_channel .close ()
0 commit comments