[英]ncurses and C- Display output of 'df' command in ncurses window
I am relatively new to ncurses and was just wondering what would be the simple way to display the output of a command executed in terminal/the command line in the ncurses TUI that I am starting.我对 ncurses 比较陌生,只是想知道在终端/命令行中显示我正在启动的 ncurses TUI 中执行的命令的输出的简单方法是什么。 ie something like this psuedocode (which I know doesn't work, just to get the point accross :) The goal is to present a menu screen displaying various system information like available memory, network info, etc:
即像这样的伪代码(我知道它不起作用,只是为了得到重点:) 目标是呈现一个菜单屏幕,显示各种系统信息,如可用内存、网络信息等:
#include <ncurses.h>
#include <stdlib.h>
#include <stdio.h>
int main(){
initscr();
cbreak();
char command[] = "df";
printw(system(command));
}
You can do this by opening a pipe to the command (the example should use "df"
, by the way).您可以通过打开命令的管道来完成此操作(顺便说一下,该示例应使用
"df"
)。 Something like this:像这样的东西:
#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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.