Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Unable to pipe output to grep / jq #493

Open
@srisch

Description

@srisch

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions