Skip to content

Warn when a table module reads from an interactive terminal - #9175

Open
Esteban82 wants to merge 4 commits into
masterfrom
warn-stdin-tty-terminal
Open

Warn when a table module reads from an interactive terminal#9175
Esteban82 wants to merge 4 commits into
masterfrom
warn-stdin-tty-terminal

Conversation

@Esteban82

Copy link
Copy Markdown
Member

When a module that reads a data table (blockmean, gmtinfo, psxy, triangulate, surface, mapproject, etc.) is run with no input file and no piped/redirected data, GMT falls back to reading from standard input. If you run it directly in a terminal — often just because you forgot the input file — the command appears to hang, with no indication of what it's waiting for.

Now a message appears in that case:

gmt gmtinfo
gmtinfo [WARNING]: No input file given - reading table data from standard input
(this terminal). Type your data and press Ctrl-D when done. To use a file or a
pipe instead, press Ctrl-C now and rerun the command with that input.

It's currently a warning, so the command keeps waiting on stdin as before (you can still type data and finish with Ctrl-D).

Question:
Would a hard error instead be preferred, so it exits immediately instead of continuing to wait?

Assisted by Claude Opus 5

…minal

gmtapi_init_import() (called by GMT_Init_IO, used by every table-reading
module) registered stdin as the input source whenever no files were
given, without checking whether stdin is an interactive terminal. When
a module was run with no input file and no piped/redirected data, it
would block forever waiting for keyboard input. Now we detect an
interactive stdin via isatty()/_isatty() and fail fast with a clear
error message instead.
Follow the existing gmt_notposix.h pattern used for access/fileno rather
than an ad-hoc #ifdef _WIN32 block in gmt_api.c: CMake now probes for
isatty/_isatty, and gmt_notposix.h maps _isatty to isatty on Windows.
The <unistd.h>/<io.h> includes added earlier were redundant, since
gmt_notposix.h (via gmt_dev.h) already provides both.

Also test the stream actually being registered,
API->GMT->session.std[GMT_IN], instead of the global stdin.
@Esteban82 Esteban82 added enhancement Improving an existing feature add-changelog Add PR to the changelog AI-assisted All (or most) of the code was written by Artificial Intelligence. labels Sep 3, 2026
@joa-quim

joa-quim commented Sep 3, 2026

Copy link
Copy Markdown
Member

gmtinfo is a particular module. All other mentioned here (blockmean, etc) print the online help when only the program names is typed. I think this would introduce unnecessary complication for very little gain to distinguish when options were passed but not the file name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add-changelog Add PR to the changelog AI-assisted All (or most) of the code was written by Artificial Intelligence. enhancement Improving an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants