I am using MSYS2 (x86-64, installed with the 20150916 and updated using pacman
to the latest default packages as of two days ago) but I ended up encountering the same error (which makes sense as MSYS2 is a cygwin derivative). I never had this with MSYS, but since MSYS is kind of dead and I wanted more modern tools I am switching to MSYS2 and porting my scripts. I found a workaround that is working for me at the moment:
$ echo hi | cmd //c "cat | sqlcmd"
I assume it works because we’re asking cmd
to set up the pipe between the MSYS2 process (cat
) and the Windows process rather than letting MSYS2/bash
do it. Though I also suspect that SQLCMD
is doing some evil nasty trickery from Windows programming in the ’90s which it shouldn’t be doing in the first place making it a special case which perhaps deserves a workaround be developed in cygwin/MSYS2.
Note that with this method passing arguments to sqlcmd
becomes really difficult, especially if you want to pass a literal "
.
Full output from me demonstrating the error, its solution, and showing where my sqlcmd
is coming from:
ohnob@WIN-F5A6PNAUAJ2 ~
$ echo hi |sqlcmd -S localhost\\SQLEXPRESS12
Sqlcmd: Error: Internal error at ReadTextLine (Reason: Unspecified error).
ohnob@WIN-F5A6PNAUAJ2 ~
$ echo hi | cmd //c "cat | sqlcmd -S localhost\\SQLEXPRESS12"
Msg 2812, Level 16, State 62, Server WIN-F5A6PNAUAJ2\SQLEXPRESS12, Line 1
Could not find stored procedure 'hi'.
ohnob@WIN-F5A6PNAUAJ2 ~
$ which sqlcmd
/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/110/Tools/Binn/sqlcmd
ohnob@WIN-F5A6PNAUAJ2 ~
$ WHERE cat | head -n 1
C:\msys64\usr\bin\cat.exe