Skip to content

How to know if there is stdout/stderr beforehand #717

Answered by ronf
isamu-isozaki asked this question in Q&A
Discussion options

You must be logged in to vote

The way you are setting term_type on the create_process() call looks ok. Note that you should no longer need the stderr=asyncssh.STDOUTonce you've done that, as settingterm_type` automatically requests a PTY, and that causes stdout and stderr to automatically be merged.

Your sample code seems to be sending the "id" command twice, and the read() call seems to be in the wrong place relative to the second write() of the command. The real problem here, though, is that you need to keep reading data in a loop to make sure you get all of it. This is why it is important to have some kind prompt you can wait for. That way, instead of just calling read(999), you can do something like a readuntil()

Replies: 1 comment 11 replies

Comment options

You must be logged in to vote
11 replies
@isamu-isozaki
Comment options

@ronf
Comment options

ronf Nov 20, 2024
Maintainer

@isamu-isozaki
Comment options

@ronf
Comment options

ronf Nov 21, 2024
Maintainer

Answer selected by isamu-isozaki
@isamu-isozaki
Comment options

@ronf
Comment options

ronf Nov 21, 2024
Maintainer

@isamu-isozaki
Comment options

@ronf
Comment options

ronf Nov 21, 2024
Maintainer

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