mirror of
https://github.com/naruxde/revpicommander.git
synced 2026-08-16 13:47:04 +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:
|
except Exception:
|
||||||
return True
|
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.
|
Send simple command to ssh host.
|
||||||
|
|
||||||
:param cmd: Shell command to execute on remote host
|
:param cmd: Shell command to execute on remote host
|
||||||
:param timeout: Timeout for execution
|
:param timeout: Timeout for execution
|
||||||
|
:param stdin: Send this string to stdin
|
||||||
:return: Tuple with stdout, stderr, exit status
|
:return: Tuple with stdout, stderr, exit status
|
||||||
"""
|
"""
|
||||||
if not self.connected:
|
if not self.connected:
|
||||||
@@ -200,7 +201,7 @@ class SSHLocalTunnel:
|
|||||||
|
|
||||||
# Running async command from sync context
|
# Running async command from sync context
|
||||||
async def _exec():
|
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
|
return result.stdout, result.stderr, result.exit_status
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user