title: Trying to get terminal $COLUMNS in Java
body: <p>I'm currently trying to get the number of columns the terminal has in Java. For that I know there is an environment variable $COLUMNS, so I try to run 'echo $COLUMNS' and read its output, but for some weird reason I get a value that makes no sense, and on top of that, I always get the same value, no matter how I resize the terminal.</p>
  
  <p>This is my code:</p>
  
  <pre><code>public static final String[] COLS = {"/bin/sh", "-c", "echo $COLUMNS &lt;/dev/tty"};
  
      public int getColumns(){
      try{
          Process p = Runtime.getRuntime().exec(CONST.COLS);
          p.waitFor();
          InputStreamReader in = new InputStreamReader(p.getInputStream());
          int cols = in.read();
          return cols;
      }catch(Exception e){
          System.out.println(e);
      }
      return 0;
      }
  </code></pre>