levant icon indicating copy to clipboard operation
levant copied to clipboard

Unable to pipe output to grep / jq

Open srisch opened this issue 1 year ago • 0 comments

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

srisch avatar Jun 29 '23 13:06 srisch