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

stdin support #4

Open
PgBiel opened this issue Jan 17, 2024 · 1 comment
Open

stdin support #4

PgBiel opened this issue Jan 17, 2024 · 1 comment

Comments

@PgBiel
Copy link

PgBiel commented Jan 17, 2024

Hello,
Thanks for the great library! I'm new to Gleam, and this seems very useful to program abstractions around shell commands and such.

I'd like to ask, are there any plans for tools to work with stdin? In particular:

  1. Being able to provide a certain string (or bytes) as the full standard input to a program;
  2. Being able to redirect all stdin received by the Gleam program to the input of the program being run (something akin to LetBeStdin);
  3. Being able to pipe a program's stdout to another program's stdin in an efficient manner (could be platform-restricted if needed). This could require a deeper rework (to e.g. use some sort of Process type), but I still think that could be very handy when working with e.g. lots of data in the shell.

Thanks in advance!

@tynanbe
Copy link
Owner

tynanbe commented Feb 28, 2024

Thanks, @PgBiel, those are some great ideas.

For my thoughts about the future of this library, check #5 (comment)

As for stdin, shellout should already be as transparent as possible about it, meaning it should be possible to pipe stdin to a command already in many cases. In other words, LetBeStdin shouldn't be necessary, but Erlang itself has some limitations with stdin, as I recall. Potentially in the future, I'll provide a NIF (possibly with a number of precompiled binaries available) I've been toying with that has solved my previous frustrations with Erlang.

I'll definitely consider your other suggestions when I start working on shellout v2.0.

For the time being, I think your first and third ideas might be currently doable as, e.g.

shellout.command(run: "sh", with: ["-euc", "
  echo '" <> my_string <> "' \\
    | cat
"], in: ".", opt: [LetBeStderr, LetBeStdout])

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

2 participants