How can I send the Ctrl+D command to stdin? #327
-
Hi, team! I need to send the Ctrl+D keyboard command to client = SSHClient(**host_config)
output = client.run_command('qsub')
stdin = output.stdin
stdin.write(data)
stdin.flush()
# user need to press Ctrl+D here
print(list(output.stdout)) # program stop here and not print stdout I overcame the problem by opening a shell, but there isn't other way? client = SSHClient(**host_config)
shell = client.open_shell()
shell.run('qsub')
shell.stdin.write(data)
shell.stdin.flush()
shell.close()
print(list(shell.stdout)) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi there, Your program probably expects an interactive shell to be available and can't read from stdin without one. So the interactive shell works but remote run which does not use an interactive shell does not. You could also try If the program requires an interactive shell, use General advice is: if it works with If you need to |
Beta Was this translation helpful? Give feedback.
Hi there,
Your program probably expects an interactive shell to be available and can't read from stdin without one. So the interactive shell works but remote run which does not use an interactive shell does not.
You could also try
run_command(<..>, use_pty=True)
if it is a matter of the program requiring a TTY.If the program requires an interactive shell, use
open_shell
. It depends on the program, ssh server, server config and so forth.General advice is: if it works with
ssh <host> <remote cmd>
it will work withrun_command
. That is a non-interactive remote command.If you need to
ssh <host>
then type something, useopen_shell
. That's an interactive shell.ssh <host> << some script here…