matklad / xshell

Apache License 2.0
695 stars 28 forks source link

Add an ability to read exit code and specific streams #89

Closed Deniallugo closed 3 months ago

Deniallugo commented 4 months ago

Description

This PR enhances the functionality of the crate by adding the ability to read both the necessary stream and the exit code of a process.

Motivation

First, I want to commend you on creating such a fantastic crate. It has significantly streamlined my work with processes, saving me a lot of time and effort.

The current implementation assumes that the presence of stderr indicates a non-zero exit code, which is not always accurate. In my application, this distinction is crucial because I need to print stdout directly while only reading stderr. Additionally, not having direct access to the exit status forces me to parse stderr for all possible scenarios, making the process error-prone and inefficient.

Check status doesn't fulfill my needs, because I'm either getting the exit status or stderr. And I'd like to have both

Changes

Added functionality to read the exit code of a process altogether with the specified stream.

matklad commented 4 months ago

:thinking: I think the idea is that this use-case should be handled by the fn output method, which returns an std::process::Output -- the most low-level and flexible interface.

So, I'd rather not add an extra StreamOutput type, and keep only two levels of abstraction:

Though, as it stands I think fn output doesn't allow the logic of "inherit stdout, but capture stderr", it always captures both.


In terms of actionable things:

Deniallugo commented 4 months ago

Great, Thank you! I'll try this direction!