4

I am using Git Bash on Windows, trying to pretty print JSON output using the command line. Following this answer, I try the following:

$ echo '{"print": "this"}' | python -m json.tool
stdin is not a tty

My Python version is 2.7.15 (Anaconda).

When I try the same using the native Windows cmd, it works correctly (but I want to use Bash).

phd
  • 82,685
  • 13
  • 120
  • 165
Alon
  • 699
  • 2
  • 9
  • 17

1 Answers1

10

Would echo '{"print": "this"}' | python.exe -m json.tool works better in a git bash session (adding .exe to python).

That seems to be a winpty issue, as shown here.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks, adding the `.exe` suffix seems to work. The reason is still mysterious to me. I added an alias to avoid typing it everytime: `alias python='winpty python.exe` – Alon Jan 21 '19 at 10:51
  • @G.Alon Good call on the alias, I had to do that too. Don't forget that, if you are using a recent enough Windows 10, you could install and use a (fully Linux) Git/python on WSL (https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux), in which case you won't have any pty issue. – VonC Jan 21 '19 at 11:11