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

Unable to pipe output to grep / jq #493

Open
srisch opened this issue Jun 29, 2023 · 0 comments
Open

Unable to pipe output to grep / jq #493

srisch opened this issue Jun 29, 2023 · 0 comments

Comments

@srisch
Copy link

srisch commented Jun 29, 2023

Description
Piping output from levant into a program doesn't work, everything goes to stderr.

Plan any job with the following command on linux and you can see that it's output is going to stderr. I'd expect you could grep for a string change, or pipe json results into jq which makes reading large jobs easier.

levant plan somejob.nomad | grep "a string you expect" - Grep doesn't work
levant plan somejob.nomad |& grep "a string you expect" - Grep does work as stderr is combined into stdout

This helpful command will show stderr vs stdout
{ { levant plan yourjob.nomad; } 2>&3 | sed 's/^/STDOUT: /'; } 3>&1 1>&2 | sed 's/^/STDERR: /'

The issue appears to be within the os.Stdout.Fd check as when you pipe levant's output this check returns false causing everything to go to stderr.

if isatty.IsTerminal(os.Stdout.Fd()) ||
	isatty.IsCygwinTerminal(os.Stdout.Fd()) {
	logWriter = conswriter.GetTerminal()
} else {
	logWriter = os.Stderr
}

Output of levant version:

Levant v0.3.3-dev
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

1 participant