summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThalia Archibald <thalia@archibald.dev>2024-11-01 00:10:30 -0700
committerEmanuele Torre <torreemanuele6@gmail.com>2024-11-08 19:07:55 +0100
commit7a1fd72d2d3fd6593018aacea9288de450400e79 (patch)
tree2d42ffc55cd8b75a28955cf18b5826d86dbbf8ae
parent0558e77e8c0cc4c6250ebddd1cddcb63bbf33615 (diff)
Fix missing program from file
When jq is not supplied with a program, it usually exits with an error and usage text, except for when jq is not connected to a TTY (i.e., not interactive), in which case a default program of `.` is used. Combined with `-f`, it then tries to read `.` as the filename. $ jq jq - commandline JSON processor [version 1.7.1] … $ jq -f jq - commandline JSON processor [version 1.7.1] … $ jq | cat ^C $ jq -f | cat jq: Could not open .: It's a directory
-rw-r--r--src/main.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index ccc73e9a..e2cae73a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -587,7 +587,7 @@ int main(int argc, char* argv[]) {
jq_set_attr(jq, jv_string("VERSION_DIR"), jv_string_fmt("%.*s-master", (int)(strchr(JQ_VERSION, '-') - JQ_VERSION), JQ_VERSION));
#ifdef USE_ISATTY
- if (!program && (!isatty(STDOUT_FILENO) || !isatty(STDIN_FILENO)))
+ if (!program && !(options & FROM_FILE) && (!isatty(STDOUT_FILENO) || !isatty(STDIN_FILENO)))
program = ".";
#endif