Skip to content

Return matched group in ShellStream.Expect #833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
NN--- opened this issue May 30, 2021 · 9 comments
Closed

Return matched group in ShellStream.Expect #833

NN--- opened this issue May 30, 2021 · 9 comments
Labels
Milestone

Comments

@NN---
Copy link

NN--- commented May 30, 2021

Currently it returns the strings which requires me to call Regex.Match second time.

@IgorMilavec
Copy link
Collaborator

I have created a discussion #926 for all ShellStream related issues.

@IgorMilavec
Copy link
Collaborator

@nn I'm trying to better understand usage patterns related to Expect API. Can you please explain how you use it and if possible provide a proto code for it?

@NN---
Copy link
Author

NN--- commented Mar 21, 2022

The API reads the data and tries to
match it with the given pattern.
Once it is matched the method returns.
The problem here is that I want the matched groups what API doesn't give.

If you talk generally about the API, it would be better to have a Stream abstraction over SSH, then such code could be implemented for any stream.

@IgorMilavec
Copy link
Collaborator

Yes, I know what the Expect API is supposed to do. :)
What I'm asking is how you are using it? I agree that having such functionality for any Stream would be beneficial, but to design it properly, we first need to understand how it is used in the client code. So if you could describe why and how you are using it would help me very much.

@NN---
Copy link
Author

NN--- commented Mar 21, 2022

One of usages is to wait for password prompt when sudo is called and put a password.

@IgorMilavec
Copy link
Collaborator

So in this case you would be Expecting $".*\[sudo\] password for {RegexEscape(username)}: "?

@NN---
Copy link
Author

NN--- commented Mar 21, 2022

Yes, this is the idea.
It is one of the possible usages of Expect of course.

@NN---
Copy link
Author

NN--- commented Mar 21, 2022

In general any command requiring input needs to wait for the prompt and only then put the text.

@WojciechNagorski WojciechNagorski added this to the vNext milestone Sep 29, 2023
@jscarle
Copy link
Contributor

jscarle commented Feb 13, 2024

@IgorMilavec @WojciechNagorski Although the conversation is unclear, I believe this was also fixed by #1207 and #1319.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants