From 7a1fd72d2d3fd6593018aacea9288de450400e79 Mon Sep 17 00:00:00 2001 From: Thalia Archibald Date: Fri, 1 Nov 2024 00:10:30 -0700 Subject: [PATCH] Fix missing program from file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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