![]() ![]() In particular, the same thing shown above can also be achieved more succinctly with the ExecuteBufferedAsync() extension method: Handling command output is a very common use case, so CliWrap offers a few high-level execution models to make these scenarios simpler. This example command is configured to decode the data written to standard output and error streams as text, and append it to the corresponding StringBuilder buffers.Īfter the execution is complete, these buffers can be inspected to see what the process has printed to the console. Contains stdOut/stdErr buffered in-memory as string var stdOut = stdOutBuffer. Continue reading below! var result = await Cli. ⚠ This particular example can also be simplified with ExecuteBufferedAsync(). You can change this by calling WithStandardInputPipe(.), WithStandardOutputPipe(.), or WithStandardErrorPipe(.) to configure pipes for the corresponding streams: You can override this behavior by disabling result validation using WithValidation(CommandResultValidation.None).īy default, the process's standard input, output and error streams are routed to CliWrap's equivalent of the null device, which represents an empty source and a target that discards all data. #Clipwrap pc codeThe code above spawns a child process with the configured command line arguments and working directory, and then asynchronously waits for it to exit.Īfter the task has completed, it resolves to a CommandResult object that contains the process exit code and other related information.ĬliWrap will throw an exception if the underlying process returns a non-zero exit code, as it usually indicates an error. Result contains: // - result.ExitCode (int) // - result.StartTime (DateTimeOffset) // - result.ExitTime (DateTimeOffset) // - result.RunTime (TimeSpan) Once the command is configured, you can run it by calling ExecuteAsync(): To build a command, start by calling Cli.Wrap(.) with the executable path, and then use the provided fluent interface to configure arguments, working directory, or other options. Similarly to a shell, CliWrap's base unit of work is a command - an object that encodes instructions for running a process. □ Watch Intro to CliWrap on YouTube for a deep look into the library and its features!
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |