{"record":{"id":"004c2b3a99e5a21a","repo":"imsnif/bandwhich","slug":"failed-to-get-stdout-if-you-are-trying-to-pipe-b","errorCode":null,"errorMessage":"Failed to get stdout: if you are trying to pipe 'bandwhich' you should use the --raw flag","messagePattern":"Failed to get stdout: if you are trying to pipe 'bandwhich' you should use the --raw flag","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main.rs","lineNumber":63,"sourceCode":"    if let Some(ref log_path) = opts.log_to {\n        let log_file = File::options()\n            .write(true)\n            .create_new(true)\n            .open(log_path)?;\n        WriteLogger::init(\n            opts.verbosity.log_level_filter(),\n            Default::default(),\n            log_file,\n        )?;\n    }\n\n    let os_input = os::get_input(opts.interface.as_deref(), !opts.no_resolve, opts.dns_server)?;\n    if opts.raw {\n        let terminal_backend = RawTerminalBackend {};\n        start(terminal_backend, os_input, opts);\n    } else {\n        let Ok(()) = terminal::enable_raw_mode() else {\n            bail!(\n                \"Failed to get stdout: if you are trying to pipe 'bandwhich' you should use the --raw flag\"\n            )\n        };\n\n        let mut stdout = std::io::stdout();\n        // Ignore enteralternatescreen error\n        let _ = crossterm::execute!(&mut stdout, terminal::EnterAlternateScreen);\n        let terminal_backend = CrosstermBackend::new(stdout);\n        start(terminal_backend, os_input, opts);\n\n        // Ensure terminal is restored after exit (handles SIGINT case).\n        // These operations are idempotent, so safe to call even if 'q' already cleaned up.\n        let _ = terminal::disable_raw_mode();\n        let _ = crossterm::execute!(std::io::stdout(), terminal::LeaveAlternateScreen);\n    }\n    Ok(())\n}\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/imsnif/bandwhich/blob/1899870cea8bb377948f05cfea64733ec6ea2cd6/src/main.rs#L45-L81","documentation":"bandwhich's normal (non --raw) mode requires a TTY so it can put the terminal into raw mode for its TUI. When `terminal::enable_raw_mode()` fails (typically because stdout is a pipe, not a terminal), it aborts with this message pointing the user to the --raw flag.","triggerScenarios":"Running bandwhich and piping/redirecting its output (e.g. `bandwhich | grep ...`, `bandwhich > out.txt`) without `--raw`, so `enable_raw_mode()` returns Err.","commonSituations":"Users piping bandwhich output into another process or a file, running it in CI or scripts, capturing output in an IDE terminal without a pty.","solutions":["Add the --raw flag when piping: `bandwhich --raw | your-consumer`","Run bandwhich directly in an interactive terminal when you want the TUI","If invoking programmatically, check `isatty(stdout)` first and pass --raw when false"],"exampleFix":"// before\nbandwhich | grep chromecast\n// after\nbandwhich --raw | grep chromecast","handlingStrategy":"validation","validationCode":"use std::io::IsTerminal;\nlet interactive = std::io::stdout().is_terminal();\nlet needs_raw_flag = !interactive; // pass --raw when output is piped\nif needs_raw_flag { args.push(\"--raw\"); }","typeGuard":null,"tryCatchPattern":"// shell wrapper\nif [ -t 1 ]; then bandwhich \"$@\"; else bandwhich --raw \"$@\"; fi","preventionTips":["Pass --raw whenever output is piped or redirected","Check `test -t 1` (stdout is a TTY) before invoking without --raw","In scripts/CI always use --raw","Remember the TUI needs a real terminal; capture mode does not"],"tags":["rust","cli","terminal","tty"],"backgroundTag":"invalid-cli-argument","analyzedSha":"1899870cea8bb377948f05cfea64733ec6ea2cd6","analyzedAt":"2026-09-08T10:26:38.858Z","contentChangedAt":"2026-09-08T10:26:38.858Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}