简体   繁体   English

为什么我在使用 minicom 时无法在 Linux C 程序中获取窗口大小?

[英]Why do I can't get window size in Linux C program while I'm using minicom?

I have some board with Linux on it.我有一些带有 Linux 的板子。 I need to get window size in program.我需要在程序中获取窗口大小。 User can be connected to the board by minicom or ssh .用户可以通过minicomssh连接到开发板。 When I run my program while I'm using ssh all OK, I can get terminal window size.当我在使用ssh时运行我的程序一切正常,我可以获得终端窗口大小。 But when I run it while I'm using minicom I get only zeroes.但是当我在使用minicom时运行它时,我只得到零。 Why does it happens and how can I get a terminal window size in both cases?为什么会发生这种情况以及如何在两种情况下获得终端窗口大小?

Here is my code:这是我的代码:

struct winsize win;

ioctl(STDIN_FILENO, TIOCGWINSZ, &win);

printf("lines %d\n", win.ws_row);
printf("columns %d\n", win.ws_col);

As noted by @Ruslan, one of the answers to How to get terminal window width?正如@Ruslan 所指出的, 如何获得终端窗口宽度的答案之一 mentions that the usual way to get the screensize via a system call does not work over a serial line.提到通过系统调用获取屏幕大小的常用方法不适用于串行线路。

If minicom supported the VT100 cursor-position report , then you could use resize on the remote shell command-line to set the size.如果minicom支持 VT100 cursor-position report ,那么您可以在远程 shell 命令行上使用resize来设置大小。 resize uses the cursor-position report to determine the actual size of the screen, prints the result and (the point of this question) updates the terminal settings which tell other applications what the screen size is. resize使用光标位置报告来确定屏幕的实际大小,打印结果并(这个问题的重点)更新终端设置,告诉其他应用程序屏幕大小是什么。 That only lasts for the current connection.这仅适用于当前连接。 You can see the effect using the stty command.您可以使用stty命令查看效果。 In this example, my window is 40x80:在这个例子中,我的窗口是 40x80:

$ resize;stty -a
set noglob;
setenv COLUMNS '80';
setenv LINES '40';
unset noglob;
speed 38400 baud; rows 40; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany -imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke -flusho -extproc

The question is unclear (there are several copies of minicom), at least the Debian source for it seems to support that (look for 'n' as a start).问题不清楚(有几个 minicom 副本),至少它的Debian 源代码似乎支持这一点(以'n'作为开头)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在这个带有C(LINUX)线程的小程序中得到这些结果? - Why do I get these results in this small program with threads in C (LINUX)? 如果我在 C 中大小完全相同的两个字符串上使用 strcpy(),为什么程序会停止? - Why does the program stop if I'm using strcpy() on two strings with the exact same size in C? 为什么我不能让这个简单的 C 程序工作? - Why can't i get this simple C program to work? 我在 C 中制作一个简单的 pthreads 程序时遇到分段错误,我不明白为什么 - I get segmentation fault while making a simple pthreads program in C and I don't understand why 如何使用C / C ++系统调用获取Linux中进程的堆内存的当前大小? - How do I get the current size of the heap memory of a process in Linux using C/C++ system calls? 如何使用在Linux上运行的C语言程序获取驱动器的确切总空间? - How can I get exact total space of a drive using C language program running on Linux? 当我在终端窗口的 Linux Mint 上编译具有 getchar() 等的程序时,我没有得到输出 - I don't get an output when I compile a program having getchar(), etc on Linux Mint on the terminal window 在Linux Mint 15中执行C程序时,为什么会出现错误“ bash:./ a.out:权限被拒绝” - Why do I get the error “bash: ./a.out: Permission denied” when I execute a C program in Linux mint 15 在C编程中,我试图使用指针反向打印数组,但似乎无法获取它 - In C programming, I'm trying to print my array in reverse using pointers but I can't seem to get it 为什么执行此C程序时会出现分段错误? - Why do i get a segmentation fault when executing this C program?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM