Submitting one command, but getting output from previous #782
Replies: 1 comment 1 reply
-
|
It sounds to me like you may have forgotten to read until you see the initial prompt sent by the shell when the session is started before sending the first command. As a result, instead of matching the prompt after the command, you are matching the prompt before it. Then, when you send the second command, the following reads return the first command's output, and this mismatch continues for all future commands you send. Also, keep in mind that you'll probably also want to read and skip over the echo of the commands you are sending by the shell. Otherwise, that'll be mixed into the command's output when you read that. After seeing the prompt, you could do a single call to readline() to return that, assuming you aren't sending multi-line commands. Also, I would recommend using readuntil() to try and match on prompts. That way, if there is more output after prompt, you won't read that. That shouldn't happen if you wait for the first prompt before sending the first command, but it's cleaner and simpler to do the readuntil() than to implement it yourself using a plain read(). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've just experience a situation in which I've submitted two commands. But instead of the response for the second one, I've received a response from the first one.
I cannot locally reproduce it with the two commands that I've ran in production (it happened just once, and I'm using
asyncsshfor so many other commands, with no problem ever, or at least I didn't notice).This is a simplified flow of how I submit my commands:
First command I submit takes roughly a couple of seconds to finish:
Second command is super fast, but returns big response
But after submitting second command, and reading through the output, I've received 1st command with it's output.
I submit all the commands one by one. There's no chance that they overlapped.
Any idea how would it be possible?
Beta Was this translation helpful? Give feedback.
All reactions