Following the streaming API example, I tried a few things and am not sure why they are not working.
Check out this script:
import asyncio
import asyncssh
@asyncio.coroutine
def run_client():
conn, client = yield from asyncssh.create_connection(host='localhost', client_factory=None)
stdin, stdout, stderr = yield from conn.open_session('ls')
output = yield from stdout.read()
print(output, end='')
print("status: ", stdout.channel.get_exit_status())
print("signal: ", stdout.channel.get_exit_signal())
stdin, stdout, stderr = yield from conn.open_session('ls; date')
output = yield from stdout.read()
print(output, end='') # only shows output from the ls
print("status: ", stdout.channel.get_exit_status())
print("signal: ", stdout.channel.get_exit_signal())
stdin, stdout, stderr = yield from conn.open_session() # assuming I am invoking a shell here, since there is no input command
stdin.write("false\n")
output = yield from stdout.read() # hangs, presumably because there is no output?
print(output, end='')
print("status: ", stdout.channel.get_exit_status()) # I expect a 1 here
print("signal: ", stdout.channel.get_exit_signal())
conn.close()
try:
asyncio.get_event_loop().run_until_complete(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
My first command, ls, works fine by itself. However I can’t seem to combine commands with a semicolon, like ls; date, as only the output from the first command shows.
And running a command like false (which exits with a 1 and doesn’t print output) also seems to be problematic.
What’s the correct way to approach these tasks?
--
Visit the AsyncSSH home page at http://asyncssh.timeheart.net
---
You received this message because you are subscribed to the Google Groups "asyncssh-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to asyncssh-user...@googlegroups.com.
To post to this group, send email to asyncss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/asyncssh-users/2648f98f-22b5-47d2-ad66-0dd9ec6ae814%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I’ll wait for the patch regarding multiple commands on one line. Thanks for getting to the root of the issue.
As for the shell behavior, makes sense. If I try:
stdin, stdout, stderr = yield from conn.open_session(‘false’)
output = yield from stdout.read()
print(output, end=’’)
I get the expected output, no hanging.
Thank you for thoroughly addressing my questions.
Nick
I’ll wait for the patch regarding multiple commands on one line. Thanks for getting to the root of the issue.
As for the shell behavior, makes sense. If I try:
stdin, stdout, stderr = yield from conn.open_session(‘false’) output = yield from stdout.read() print(output, end=’’)I get the expected output, no hanging.
Thank you for thoroughly addressing my questions.