1

I have downloaded the program jq-win64.exe from 'https://stedolan.github.io/jq/' and installed the program in a folder C:\Program Files\jq\ on my computer. I have also added the PATH to the program to the end of the systemvariable string in Windows 10 : . . . ;C:\Program Files\curl\;C:\Program Files\jq\

In one terminal window in Visual Studio Code I am running a server. In another terminal window I am trying to execute the command curl -s localhost:3000 | jq

Terminal window 1: C:\Users\SteinarV\PROFF_JAVASCRIPT\PROJECT\smartHouse

node server.js API running on port 3000

Terminal window 2: C:\Users\SteinarV\PROFF_JAVASCRIPT\PROJECT\smartHouse>curl -s localhost:3000 | jq

'jq' is not recognized as an internal or external command, operable program or batch file

... and do not understand why jq is not recognized. Can someone help ?

SteinarV
  • 35
  • 1
  • 7
  • Perhaps because the binary is called jq-win64 ? What does `dir c:\jq*.exe /s` return ? – Marged Jun 06 '20 at 22:46
  • dir c:\jq*.exe /s returns . . . Volume in drive C is OS Volume Serial Number is 48C3-C434 Directory of c:\Program Files\jq 06.06.2020 22:59 3 525 307 jq.exe 1 File(s) 3 525 307 bytes . . . so it looks like the program is recognized. But the command curl -s localhost:3000 | jq . . . is not working – SteinarV Jun 06 '20 at 23:35
  • Reboot the computer and try again – Marged Jun 06 '20 at 23:39

1 Answers1

3

I have downloaded the program jq-win64.exe from 'https://stedolan.github.io/jq/' and installed the program in a folder C:\Program Files\jq\ on my computer.

As you have indicated, you have a file called jq-win64.exe but you are trying to execute the command jq. You either need to rename the file to jq.exe or you need to use the command jq-win64.

For a detailed explanation of how Windows finds and executes a program in your path when you enter a command, see The Windows NT Command Shell: Command Search Sequence. Specifically:

...The shell now searches each directory specified by the PATH environment variable, in the order listed, for an executable file matching the command name. If a match is found, the external command (the executable file) executes...

...If the command name does not include a file extension, the shell adds the extensions listed in the PATHEXT environment variable, one by one, and searches the directory for that file name. Note that the shell tries all possible file extensions in a specific directory before moving on to search the next directory (if there is one)...


You indicate in the comments the same error persists even when the filenames match. Note that each running program has its own set of environment variables, and these aren't updated by global changes. You need to close and reopen cmd.exe windows after making a global change. See also Adding directory to path environment variable in windows. You can use the path command to verify whether a particular terminal session has inherited the PATH variable you defined, thus narrowing your problem.


You indicate that the problem still persists. You need to use the tools available to you to narrow it down further:

Try running the program with its full path:

"C:\Program Files\jq\jq-win64.exe" --help

This will confirm that the program is present where you think it is and can be run from the terminal.

Try running the program with no path and its extension:

jq-win64.exe --help

If this works but running the program without an extension doesn't, you might have set PATHEXT to something that doesn't include ".EXE".

Try setting the path explicitly in the terminal to contain only the program directory and nothing else, then run it with its full extension:

set PATH=C:\Program Files\jq
jq-win64.exe --help

(Note that after this test you'll need to close the terminal window and start a new one to reset the path.)

If this works, perhaps you have a mismatch in your path.

Weeble
  • 14,415
  • 3
  • 50
  • 66
  • I have changed the name of the program to jq.exe . . . but when I try to execute curl -s localhost:3000 | jq . . . in the terminal window 'C:\Windows\System32\cmd.exe' I get 'jq' is not recognized. I have also tried Git Bash. SteinarV@workstation00 MINGW64 ~/PROFF_JAVASCRIPT/PROJECT/smartHouse (master) $curl -s localhost:3000 | jq . . . result : bash: jq: command not found (23) Failed writing body – SteinarV Jun 06 '20 at 23:13
  • What shows when you run the `path` command in that terminal? Does it show the path that you set? – Weeble Jun 06 '20 at 23:24
  • When I run the path command in the terminal I get . . . all paths on my computer . . . and ;C:\Program Files\jq\ . . . so it shows the path that I have set – SteinarV Jun 07 '20 at 01:26
  • I don't really have enough information to solve this for you. You'll need to try narrowing it down like I've explained - try to get it down to the minimal situation that reproduces the problem. Can you run it at all from the terminal? Do you still have problems even with everything else removed from the PATH? (To be clear, I don't recommend removing everything from the global path, just using `set` to test it in a terminal window.) – Weeble Jun 07 '20 at 03:05
  • 1) This test is working : C:\>"C:\Program Files\jq\jq.exe" --help Output : jq - commandline JSON processor [version 1.6] Usage: C:\Program Files\jq\jq.exe [options] [file...] C:\Program Files\jq\jq.exe [options] --args [strings...] C:\Program Files\jq\jq.exe [options] --jsonargs [JSON_TEXTS...] jq is a tool for processing JSON inputs, applying the given filter to its JSON text inputs and producing the filter's results as JSON on standard output . . . . and more – SteinarV Jun 07 '20 at 10:58
  • 2) This test is not working : C:\>jq.exe --help 'jq.exe' is not recognized as an internal or external command, operable program or batch file. – SteinarV Jun 07 '20 at 10:58
  • 3) This test is not working : C:\>set PATH=C:\Program Files C:\>jq-win64.exe --help 'jq-win64.exe' is not recognized as an internal or external command, operable program or batch file. C:\> – SteinarV Jun 07 '20 at 10:59
  • 4) Comment : I can use curl without jq if I remove the '| jq' from the end of the curl command 'curl -s localhost:3000 | jq' . . . but using curl with jq is very useful once the JSON becomes more complex. I am using a Unix pipe (|) to feed the output from curl into jq . . . maybe windows has a problem with that – SteinarV Jun 07 '20 at 11:00
  • Sorry, that should have been `set C:\Program Files\jq` since that's the directory the file is in. – Weeble Jun 07 '20 at 20:18
  • I'm not suggesting you don't use pipes, and they should work in Windows fine, but when trying to figure out what's going wrong, it's better to isolate the problem. Once you've figured it out and fixed it you can then worry about the full command with the pipes. – Weeble Jun 07 '20 at 20:24
  • TEST #1 : C:\TEMP>echo "Hello" | jq ". + \" world\"" Output : 'jq' is not recognized as an internal or external command, operable program or batch file. TEST #2 : C:\TEMP>set PATH=C:\Program Files\jq C:\TEMP>echo "Hello" | jq ". + \" world\"" Output : "Hello world" COMMENT : If I don't use 'set PATH' first in Windows Command Prompt the code will not work – SteinarV Jun 08 '20 at 21:06
  • WHAT I HAVE LEARNED : 1) C:\>"C:\Program Files\jq\jq.exe" --help . . . This is working 2) C:\>jq.exe --help . . . This is NOT working 'jq.exe' is not recognized as an internal or external command, operable program or batch file. 3) C:\>set PATH=C:\Program Files\jq C:\>echo "Hello" | jq ". + \" world\"" . . . This is working Output : "Hello world" – SteinarV Jun 08 '20 at 21:32
  • The command C:>path . . . in a new Terminal window returns the entire 'path string' on my computer . . . and ';C:\Program Files\jq' is included !!! . . . so why I must use 'set PATH=C:\Program Files\jq' in the Terminal before the jq command 'echo "Hello" | jq ". + \" world\"" . . ' I do not understand. – SteinarV Jun 08 '20 at 21:45
  • Hmmmm. Is there a space after `jq` in the path? Is it _really_ long? I think Windows has a limit of either 2048 or 4096 characters in an environment variable. – Weeble Jun 08 '20 at 21:48
  • PATH=C:\Program Files . . . C:\Users\SteinarV\AppData\Roaming\nvm;C:\Program Files\nodejs ;C:\Program Files\curl\ ;C:\Program Files\jq\ ;C:\Users\SteinarV\AppData\ . . . there is a space after jq and after curl. Total characters in the 'path string': less than 2048 – SteinarV Jun 09 '20 at 05:23
  • There was a space after 'curl' and 'jq' in the string PATH=C:/Program . . . ;C:\Program Files\curl\ ;C:\Program Files\jq\ ;C:\User . . . When I removed the space, the command 'curl -s localhost:3000 | jq' can be executed . . . jq.exe is recognized. The problem is solved. Thanks for all help @weeble. – SteinarV Jun 09 '20 at 16:32