我对ncurses比较陌生,只是想知道如何简单地显示我正在启动的ncurses中终端/命令行中执行的命令的输出。例如,类似于这个psuedocode (我知道它不起作用,只是为了解决问题:),其目标是显示一个菜单屏幕,显示各种系统信息,如可用内存、网络信息等:
#include <ncurses.h>
#include <stdlib.h>
#include <stdio.h>
int main(){
initscr();
cbreak();
char command[] = "df";
printw(system(command));
}发布于 2016-07-08 20:42:27
您可以通过向命令打开管道(顺便说一句,示例应该使用"df" )来做到这一点。就像这样:
#include <ncurses.h>
#include <stdlib.h>
#include <stdio.h>
int
main(void)
{
FILE *pp;
initscr();
cbreak();
if ((pp = popen("df", "r")) != 0) {
char buffer[BUFSIZ];
while (fgets(buffer, sizeof(buffer), pp) != 0) {
addstr(buffer);
}
pclose(pp);
}
getch();
return EXIT_SUCCESS;
}https://stackoverflow.com/questions/38274985
复制相似问题