Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, all, I use ioctl to get the cosole window size (the SSH window). I use the following code: ------------- struct winsize ws; int returnValue = ioctl(pCommandStructure->terminal, TIOCGWINSZ, &ws); int ...
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Posts
    4

    get the cosole window size: why ioctl always return 0 width?

    Hi, all,
    I use ioctl to get the cosole window size (the SSH window). I use the following code:

    -------------
    struct winsize ws;
    int returnValue = ioctl(pCommandStructure->terminal, TIOCGWINSZ, &ws);
    int numberOfColumnsOfTerminalWindow = ws.ws_col;
    -------------

    When I debug on linux pc, it gives me the correct window width. But after I try it on router (this is my enventual place where my code shall run), ioctl always give me 0 width, that is, numberOfColumnsOfTerminalWindow == 0. but the returnValue is 0 which means that the function call succeeds.

    Can anyonen tell me what is the problem and how to solve it?

    Thanks a lot.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Using ioctl() for this is very problematic since they are VERY system dependent. It is not recommended usage. I'm not sure what the best system API call would be, but "stty size" will return the current tty console size in rows and columns.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Jul 2010
    Posts
    4
    Thanks. I tried "stty size", but no matter how I change the window size, it forever returns:
    24 80

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...