Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How can I send the Ctrl+D command to stdin? #327

Answered by pkittenis
rodrigomologni asked this question in Q&A
Discussion options

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))
You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
1 reply
Comment options

Hi @pkittenis! Thank you for your detailed explanation. 🙂

Answer selected by rodrigomologni
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /