Skip to content
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

Question: Does cradle support streaming output #190

Open
fdncred opened this issue Sep 16, 2021 · 6 comments
Open

Question: Does cradle support streaming output #190

fdncred opened this issue Sep 16, 2021 · 6 comments

Comments

@fdncred
Copy link

fdncred commented Sep 16, 2021

I'm one of the maintainers of nushell and am interested in a cross-platform wrapper for std::process::Command. We have a couple requirements and I was wondering if your crate supports those.

  1. Cross-platform, meaning Windows, Mac, Linux.
  2. Support streaming of the output returned from std::process::Command.

Thanks and great work on this!

@casey
Copy link
Collaborator

casey commented Sep 17, 2021

I'm one of the maintainers of nushell and am interested in a cross-platform wrapper for std::process::Command. We have a couple requirements and I was wondering if your crate supports those.

What are you looking for in a wrapper? Just better ergonomics, or are there other requirements?

  1. Cross-platform, meaning Windows, Mac, Linux.

We test on Windows, Mac, and Linux, so everything should work.

  1. Support streaming of the output returned from std::process::Command.

We don't currently support streaming, but it seems to be a common request. I don't think we have any particular objection to adding it, although we'd have to figure out a nice API for it.

Thanks and great work on this!

Thank you for the kind words!

@fdncred
Copy link
Author

fdncred commented Sep 17, 2021

What are you looking for in a wrapper? Just better ergonomics, or are there other requirements?

right now, we shell out on most things and just call 'external' commands. external means they're not nushell built in commands. so, for windows, that would be something like cmd.exe /c c:\some\path\to\exe -with_param1 -with_param2 and for unixes, we do something like sh -c 'blah' 'param'. I don't like shelling out at all and would like to eliminate it entirely, if possible. so, i stumbled upon your crate and it looked like it may fit.

so, i'd like to fix that issue but i'm also interested in making it easier to call so we don't have to remember all the minutiae for properly launching a command.

We test on Windows, Mac, and Linux, so everything should work.

excellent!

We don't currently support streaming, but it seems to be a common request. I don't think we have any particular objection to adding it, although we'd have to figure out a nice API for it.

understood. i guess put our vote in the camp for streaming output. :)

Thanks again. Good luck!

@sabitm
Copy link

sabitm commented Dec 23, 2021

Noob here. but what exactly "streaming output" is?

I'm asking because i'm using cradle to run pacman (for installing packages) and the output looks like that pacman stuck although it actually doesn't. What i think that happened here is that the stdout isn't flushed frequently?

edit: I wondered if that is a pacman behavior if executed without a shell? (or a TTY?)

@soenkehahn
Copy link
Owner

I think there's two related but separate issues here. I'll try to explain: When a child process writes something to stdout, in cradle there's currently two things you can do with that:

  1. You can read it into memory as a whole (using StdoutUntrimmed or StdoutTrimmed). This then also means that the output will not be written to the parent's stdout, so you won't see it at all in a terminal. For smaller output this is fine, but for bigger output, it may be desirable to not read the whole output into memory at once before processing it further, but rather process the output in a streaming fashion, for example by passing it to something that implements Write.
  2. The other issue is when not capturing the child's stdout into memory, by not using e.g. StdoutUntrimmed. That will mean that the output will just be relayed to the parent's stdout in a streaming fashion.

(All this works very similarly for stderr.)

I believe this issue here is about number 1. @fdncred, please correct me if I'm wrong.

@sabitm: It sounds like your issue is number 2. Could you post a code snippet of how exactly you're calling cradle functions, please? I think there's a few places where this could go wrong, so it'd be nice to see a concrete example. (Ideally, could you do that in a new separate issue? That'd be awesome!)

@sabitm
Copy link

sabitm commented Dec 23, 2021

Thanks for your reply!

After further investigation, i can conclude that it just a different pacman's behavior if executed without a shell (cradle does nothing wrong!). When tested with different programs that does nothing special with shell features (like color, clearing, etc.), I can confirm that the program's output (stream) behave similarly when executed with cradle or shell.

If you're curious, this is like running run_result!(%"pacman -Syy")?;

@soenkehahn
Copy link
Owner

I see. Yeah, it sounds like pacman uses something like isatty to decide what it writes to stdout or stderr. Thanks for the reply!

(I think cradle could in theory support creating a PTY to change what isatty returns to an executed process and make it behave as if it were running standalone in a terminal. But right now I'm not convinced that should be in scope for cradle.)

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

No branches or pull requests

4 participants