How to know if there is stdout/stderr beforehand #717
-
Hi! This is a bit of a follow up question to #714 and I'm not sure if this is even possible, but in a process made with create_process, is there a way to know whether
to get the output, but is there a clever way to do this instead? I know there are sessions with callback for data_recieved but I was curious if there is a way through the process/if there is a known way to adapt a session to be like a process Sorry for the basic qs and again thanks for the awesome library! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 11 replies
-
Without knowing something about the output of the command (or shell) you are running, there's no way to know when to stop reading from stdout or stderr and write more data to stdin. As for stdout vs. stderr, there's really no way to know which will get written to. However, if you don't care about keeping the stdout and stderr data separate, you can combine them into a single stream by passing an argument of Your options here are basically one of the following:
|
Beta Was this translation helpful? Give feedback.
The way you are setting
term_type
on thecreate_process() call looks ok. Note that you should no longer need the
stderr=asyncssh.STDOUTonce you've done that, as setting
term_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 secondwrite()
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 callingread(999)
, you can do something like areaduntil()
…