Warn when a table module reads from an interactive terminal - #9175
Open
Esteban82 wants to merge 4 commits into
Open
Warn when a table module reads from an interactive terminal#9175Esteban82 wants to merge 4 commits into
Esteban82 wants to merge 4 commits into
Conversation
…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.
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 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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