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

Support redirected input (and send all of it on every invocation) #41

Open
tomasaschan opened this issue Sep 28, 2023 · 1 comment
Open

Comments

@tomasaschan
Copy link
Contributor

It's tempting to do something like gow run main.go < input.txt, but this will effectively run the application with that input once, and then basically freeze because the application is waiting for input but no more is coming.

gow (or some underlying library it uses) seemingly already detects that input is not a TTY, since it logs [gow] unable to read terminal state: inappropriate ioctl for device; it would be nice if it could in this case instead consume all of STDIN and store it, and then send it to the program on every invocation. If it can't detect it automatically, it could also be controlled with a flag, e.g. gow -T (for no-TTY; a lot of the good letters are already taken...).

If there's some other usage pattern that will allow me to do effectively the same thing, that'd be nice to document too! Currently I'm stuck with one terminal running gow -c build -o bin/my-app main.go and another ls bin/ | entr -rc sh -c 'bin/my-app < input.txt' which is just annoying... :)

@mitranim
Copy link
Owner

mitranim commented Sep 29, 2023

To clarify the error message you're seeing: by default, gow tries to switch the terminal into "raw mode" which allows to support hotkeys; when this operation fails, it logs this error and continues without raw mode; this can be disabled with gow -r=false.

We just want to move < input.txt from "outside" gow to "inside" each gow invocation. gow just wants to invoke one subprocess with the given arguments, and doesn't have features like redirecting stdin from a file; that's really out of scope. However, gow can be used to invoke any program including a shell script; invoking go just happens to be the default. The most practical solution for your case is a shell script. Adapting from #37 (comment):

touch go.sh
chmod +x go.sh

Content of go.sh:

#!/bin/sh

go @$ < input.txt

Usage:

gow -g=./go.sh -v -c run .

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