Beim erneuten Ausführen im Jahr 2025 ist sie teilweise kaputt.
Hier ist ein kleines Beispiel, das das Problem eingrenzt :
Code: Select all
TerminalCols.java
Code: Select all
package p5_terminal_graphics_examples;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class TerminalCols {
public static void main(String[] args) {
while (true) {
int cols = cols();
System.out.println("Terminal columns: " + cols);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
static public int cols() {
return Integer.parseInt(cmd("tput cols"));
}
static public String cmd(String args) {
return exec("sh", "-c", args);
}
static public String exec(String... cmd) {
try {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Process p;
p = Runtime.getRuntime().exec(cmd);
int c;
InputStream in = p.getInputStream();
while ((c = in.read()) != -1) {
bout.write(c);
}
in = p.getErrorStream();
while ((c = in.read()) != -1) {
bout.write(c);
}
p.waitFor();
String result = new String(bout.toByteArray());
return result.trim();
}
catch (IOException | InterruptedException e) {
return null;
}
}
}
Es wird jedoch immer der Standardwert 80 gedruckt.
Wenn ich direkt tput cols in das Terminal eingebe, wird immer die richtige Antwort zurückgegeben.
Mit der Zeit ist also etwas kaputt gegangen und ich weiß nicht, wie ich weiter herausfinden soll, wie um das zu beheben. Jede Hilfe wäre willkommen.