Skip to content

Pass-through of a Program's Standard Error #146

@jesselang

Description

@jesselang

Hello, and thank you for this wonderful package!

I'd like to use script with some programs that use standard error to prompt the user to do something before providing output. One example is ykman which prompts the user to "Touch your YubiKey...". After doing so, the program will print the one time password code to standard out. Ideally, I'd like the program's standard error to pass-through directly to os.Stderr, but it appears that script.Exec() instead interleaves the program's stderr and stdout. This means the user of this script doesn't receive the prompt from the program, and also means the prompt needs to be filtered out of the output. I'm curious if anyone has come up with a way to handle this. Below is a minimal example. Thanks!

package main

import (
	"github.com/bitfield/script"
)

func main() {
	p := script.Exec(`
		ykman oath accounts code --single "someAccountId"
	`)
	code, _ := p.String()
	script.Echo(code).Stdout()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions