-
Notifications
You must be signed in to change notification settings - Fork 152
How can I send the Ctrl+D command to stdin? #327
-
Hi, team!
I need to send the Ctrl+D keyboard command to stdin
. How can I do this?
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.
All reactions
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 with run_command
. That is a non-interactive remote command.
If you need to ssh <host>
then type something, use open_shell
. That's an interactive shell.
ssh <host> << some script here...
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 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 with run_command
. That is a non-interactive remote command.
If you need to ssh <host>
then type something, use open_shell
. That's an interactive shell.
ssh <host> << some script here EOF
or ssh <host> "my script code here"
are also examples of interactive shells.
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi @pkittenis! Thank you for your detailed explanation. 🙂
Beta Was this translation helpful? Give feedback.