charmbracelet/glow · error

unable to run command: %w

Error message

unable to run command: %w

What it means

The tokenized pager command is executed with exec.Command(fields[0], fields[1:]...) and the rendered output piped to its stdin via c.Run(). This error means the command could not start or exited abnormally: the binary is not found or not executable (exec.Error), or the pager was killed by a signal / exited non-zero / its output pipe broke.

Source

Thrown at main.go:330

	}

	// display
	switch {
	case pager || cmd.Flags().Changed("pager"):
		pagerCmd := os.Getenv("PAGER")
		if pagerCmd == "" {
			pagerCmd = "less -r"
		}

		fields, err := shell.Fields(pagerCmd, os.Getenv)
		if err != nil || len(fields) == 0 {
			return fmt.Errorf("unable to parse PAGER command: %s", pagerCmd)
		}
		c := exec.Command(fields[0], fields[1:]...) //nolint:gosec
		c.Stdin = strings.NewReader(out)
		c.Stdout = os.Stdout
		if err := c.Run(); err != nil {
			return fmt.Errorf("unable to run command: %w", err)
		}
		return nil
	case tui || cmd.Flags().Changed("tui"):
		path := ""
		if !isURL(src.URL) {
			path = src.URL
		}
		return runTUI(path, content)
	default:
		if _, err = fmt.Fprint(w, out); err != nil {
			return fmt.Errorf("unable to write to writer: %w", err)
		}
		return nil
	}
}

func runTUI(path string, content string) error {
	// Read environment to get debugging stuff

View on GitHub (pinned to e3970c813d)

Solutions

  1. Verify the pager exists: command -v $PAGER
  2. Test it directly: echo hi | $PAGER
  3. Fall back to a standard pager: PAGER=less glow README.md or unset PAGER
  4. Check the pager's exit behavior - some tools exit non-zero on quit

Example fix

# before
export PAGER='improbable-pager --dark'

# after
export PAGER='less -r'
Defensive patterns

Strategy: fallback

Validate before calling

func pagerRunnable(pagerCmd string) bool {
	fields, err := shell.Fields(pagerCmd, os.Getenv)
	if err != nil || len(fields) == 0 { return false }
	_, err = exec.LookPath(fields[0])
	return err == nil
}

Prevention

When it happens

Trigger: PAGER points at a binary that is not installed (improbable-pager, vimpager) or lacks +x; the pager crashes on the content; the pager is killed by a signal; the pager's own stdout is a broken pipe.

Common situations: PAGER set to a tool that exists on one machine but not another, pagers crashing on very large output, WSL/remote environments where the configured pager is a Windows-side binary.

Related errors


AI-assisted analysis of charmbracelet/glow@e3970c813d (2026-08-15). Data as JSON: /api/errors/df116e7ab43c6b88. Report an issue: GitHub.