mirror of
https://github.com/naruxde/revpicommander.git
synced 2026-08-16 05:45:53 +02:00
feat(ssh): Add ability to send stdin input to send_cmd
Extend the `send_cmd` function to support passing input to stdin when executing remote shell commands via SSH. Signed-off-by: Sven Sager <akira@narux.de>
This commit is contained in:
@@ -187,12 +187,13 @@ class SSHLocalTunnel:
|
||||
except Exception:
|
||||
return True
|
||||
|
||||
def send_cmd(self, cmd: str, timeout: float = None) -> Union[Tuple[str, str, int], Tuple[None, None, None]]:
|
||||
def send_cmd(self, cmd: str, timeout: float = None, stdin: str = None) -> Union[Tuple[str, str, int], Tuple[None, None, None]]:
|
||||
"""
|
||||
Send simple command to ssh host.
|
||||
|
||||
:param cmd: Shell command to execute on remote host
|
||||
:param timeout: Timeout for execution
|
||||
:param stdin: Send this string to stdin
|
||||
:return: Tuple with stdout, stderr, exit status
|
||||
"""
|
||||
if not self.connected:
|
||||
@@ -200,7 +201,7 @@ class SSHLocalTunnel:
|
||||
|
||||
# Running async command from sync context
|
||||
async def _exec():
|
||||
result = await self._conn.run(cmd, timeout=timeout)
|
||||
result = await self._conn.run(cmd, timeout=timeout, input=stdin)
|
||||
return result.stdout, result.stderr, result.exit_status
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user