我正在尝试制作一个 C 程序来选择选项。如果我以这种方式运行它,它会起作用:
./select choice{1..5}
☐ choice1 ☐ choice3 ☐ choice5
☐ choice2 ☐ choice4
# outputs "choice1 choice2" on stdout
但如果我在反引号之间运行它,那就是地狱
`./select choice{1..5}` > choices.txt
☐ choice1☐ choice2☐ choice3☐ choice4☐ choice5
# Write "choice1 choice2" in `choices.txt`
我需要能够检索选定的选项。这就是为什么我将所有输出都输出到我打开的文件中
int tty = open("/dev/tty", O_RDWR);
/* Do my program using outputs on fd `tty` */
printf("%s\n", get_results());
我认为这与tgoto
我的代码中的使用有关,用于在屏幕上移动书写光标。
if ((cm = tgetstr("cm", NULL)) == NULL)
return (-1);
tputs(tgoto(cm, x, y), fd, &my_putchar);
return (0);
我已经看到 usingisatty(1)
在反引号之间执行时返回 0,如果直接执行则返回 1... 那么,有没有办法让我在两种情况下移动光标并保持格式?
感谢您的时间