Last active
May 3, 2020 17:34
-
-
Save jcoglan/4454009 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // When I run `tput cols` in the shell, it prints '270'. | |
| // When I run `tput cols` inside a Ruby program, it returns '270'. | |
| // When I run this program, is prints '80'. | |
| // WTF? | |
| import java.lang.*; | |
| import java.io.*; | |
| public class Tput { | |
| public static void main(String[] args) throws IOException { | |
| ProcessBuilder pb = new ProcessBuilder("tput", "cols"); | |
| InputStream is = pb.start().getInputStream(); | |
| int bite = 0; | |
| StringBuffer buffer = new StringBuffer(); | |
| while (bite != -1) { | |
| bite = is.read(); | |
| buffer.append((char)bite); | |
| } | |
| System.out.println(buffer.toString()); | |
| } | |
| } |
For anyone coming across this, the ProcessBuilder has an .inheritIO method on it which your can call before .start(). This will cause the documented behavior which in turn will make tput return the expected dimensions.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One of the things I learned from my younger years of writing code for MUD/MUSHes is that the client WILL lie about it's width. It's just one of those things that only
telnetgot right, mainly becausetelnetwas the one deciding the API for this sort of shit.