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
This commit is contained in:
Thalia Archibald authored and Emanuele Torre committed 2024-11-08 19:07:55 +01:00
1 parent 0558e77e8c
commit 7a1fd72d2d
1 file changed
+1 -1
+1 -1
View File
@@ -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