-
-
Notifications
You must be signed in to change notification settings - Fork 275
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
Input prompt is not captured #191
Comments
Hey there. In general, responding to prompts is done by piping standard input data, as that's where the underlying console application reads the input from (usually separated by new lines). If you know all the prompts and the respective inputs ahead of time, you can just pre-compute the corresponding stdin string and pipe it to the command. If you need to react to prompts dynamically, the best solution is to create your own using var semaphore = new SemaphoreSlim(0, 1);
var buffer = new StringBuilder();
var stdin = PipeSource.Create(async (destination, cancellationToken) =>
{
while (!cancellationToken.IsCancellationRequested)
{
await semaphore.WaitAsync(cancellationToken);
var data = Encoding.UTF8.GetBytes(buffer.ToString());
await destination.WriteAsync(data, 0, data.Length, cancellationToken);
}
});
var cmd = stdin | Cli.Wrap("my cmd");
await foreach (var cmdEvent in cmd.ListenAsync())
{
if (cmdEvent is StandardOutputEvent stdOutEvent)
{
// Detect if it's a prompt
if (stdOutEvent.Text.Contains("Prompt"))
{
// Write the response
buffer.Clear();
buffer.AppendLine("Hello world");
semaphore.Release();
}
}
} |
Thanks for the clarification. |
What do you mean by "does not return"? |
The That particular output is not fetched by |
I don't know what |
It's weird that it would never exit. In the worst case, you can probably fool it by wrapping |
I've been having a similar problem and, adding to the discussion, I would like to suggest this feature: In the same way that the TargetPipe has a |
@vpenades it's a good idea but not super straightforward. Please make a new issue for it because this one is old. |
Version
3.6.0
Details
I have an external CLI software, that ouputs information and prompts the user for imput. I wanted to automate this and using the CliWrap in C# to wait for the prompts and then dynamically output the right user inputs (so a script is not intended).
The output of the CLI contains information used to decide on what to feed the CLI prompt.
Steps to reproduce
I know that
.ExecuteBufferedAsync()
is not what I need. It is just to reproduce the issue.The text was updated successfully, but these errors were encountered: