Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU readline: avoid prompt string in output if input is not interactive

I have a readline-based application with a prompt, however I'd like it to not show when the input is not interactive.

$ ./readline-app < command-list > result
$ cat result
prompt> Output line 1
prompt> Output line 2
prompt>
$

How can I make the prompt to not print in this case?

like image 370
Alex B Avatar asked Jan 20 '26 18:01

Alex B


1 Answers

Use isatty(3) to determine whether stdin and/or stdout are connected to a tty.

like image 182
Ignacio Vazquez-Abrams Avatar answered Jan 23 '26 08:01

Ignacio Vazquez-Abrams