Pass input to the command output #127
Replies: 1 comment 6 replies
-
This is possible but not very simple. Basically, what you need to do is create a custom Something like this (pseudocodish): public class MyPipeSource : PipeSource
{
public string Output { get; set; }
public bool IsFinished { get; set; }
public override async Task CopyToAsync(Stream destination, CancellationToken cancellationToken = default) =>
{
// Block until IsFinished is triggered, and then write the Output
// Obviously can be optimized a bit
while (!IsFinished)
await Task.Delay(100, cancellationToken);
// Encoding ideally passed to the pipe source or something
var data = Encoding.UTF8.GetBytes(Output);
await destination.WriteAsync(data, 0, data.Legnth, cancellationToken);
}
} And then do this (for example, could use other means to handle output progressively, including a custom var source = new MyPipeSource();
var cmd = source | Cli.Wrap("foo");
await foreach (var cmdEvent in cmd.ListenAsync())
{
if (cmdEvent is StandardOutputCommandEvent stdOutEvent && stdOutEvent.Text == "Password")
{
source.Output = "SuperSecurePassword";
source.IsFinished = true;
}
} Note that if the program decides to not consume standard input and exit early (for example if it doesn't ask for password), CliWrap will activate the Anyway, something like this. Let me know if this works. |
Beta Was this translation helpful? Give feedback.
-
Hello I have a situation in which I need to execute a command and then in result it ask for a password to enter. So a command is 2 step process that needs to be executed.
Can you guys please share your thoughts to achieve the same.
Beta Was this translation helpful? Give feedback.
All reactions