]> granicus.if.org Git - jq/commitdiff
Add -b / --binary option for Windows
authorNicolas Williams <nico@cryptonector.com>
Sun, 24 Mar 2019 19:39:58 +0000 (14:39 -0500)
committerNicolas Williams <nico@cryptonector.com>
Mon, 25 Mar 2019 04:23:16 +0000 (23:23 -0500)
docs/content/manual/manual.yml
src/main.c

index ef609a649661a9e0d1bbf66d2599ba2bd2373527..e721ddfa94c1f2014f5a9f4345c57fa98ab2b510 100644 (file)
@@ -164,6 +164,12 @@ sections:
         Colors can be configured with the `JQ_COLORS` environment
         variable (see below).
 
+      * `--binary` / `-b`:
+
+        Windows users using WSL, MSYS2, or Cygwin, should use this option
+        when using a native jq.exe, otherwise jq will turn newlines (LFs)
+        into carriage-return-then-newline (CRLF).
+
       * `--ascii-output` / `-a`:
 
         jq usually outputs non-ASCII Unicode codepoints as UTF-8, even
index 34d2c7e764746b7c54ff0a56502479ef78724f5b..9d539eb21916f18713f3fab957893f592b7984a6 100644 (file)
@@ -394,6 +394,16 @@ int main(int argc, char* argv[]) {
         options |= RAW_OUTPUT | RAW_NO_LF;
         if (!short_opts) continue;
       }
+      if (isoption(argv[i], 'b', "binary", &short_opts)) {
+#ifdef WIN32
+        fflush(stdout);
+        fflush(stderr);
+        _setmode(fileno(stdin),  _O_BINARY);
+        _setmode(fileno(stdout), _O_BINARY);
+        _setmode(fileno(stderr), _O_BINARY);
+        if (!short_opts) continue;
+#endif
+      }
       if (isoption(argv[i], 0, "tab", &short_opts)) {
         dumpopts &= ~JV_PRINT_INDENT_FLAGS(7);
         dumpopts |= JV_PRINT_TAB | JV_PRINT_PRETTY;