I'm trying to make a C program to select options. It works if I run it this way:
./select choice{1..5}
☐ choice1 ☐ choice3 ☐ choice5
☐ choice2 ☐ choice4
# outputs "choice1 choice2" on stdout
But if I run it between backticks, it's a hell
`./select choice{1..5}` > choices.txt
☐ choice1☐ choice2☐ choice3☐ choice4☐ choice5
# Write "choice1 choice2" in `choices.txt`
I need to be able to retrieve selected options. That is why I've done all my outputs to a file I've opened with
int tty = open("/dev/tty", O_RDWR);
/* Do my program using outputs on fd `tty` */
printf("%s\n", get_results());
I think this is related with the use of tgoto
in my code, to move the writing cursor on the screen.
if ((cm = tgetstr("cm", NULL)) == NULL)
return (-1);
tputs(tgoto(cm, x, y), fd, &my_putchar);
return (0);
I've seen that using isatty(1)
returns 0 when executed between backticks, and 1 if executed directly... So, is there a way for me to move the cursor and keep my formating in both situations?
Thank you for your time