2

This simple command fails in bash:

echo "print 'tsql'" | sqlcmd -E

it works correctly in a regular old command prompt.

It used to work with previous versions of cygwin. I've also tried inserting various flavors of unix2dos in there, and I've looked at the output with "od -c". So I'm quite sure it's not just a LF vs. CR/LF problem.

Looking at this thread: http://cygwin.com/ml/cygwin/2010-01/msg00205.html

leads me to believe something got broken in cygwin, but I've been unable to chase down any more leads.

Does anyone have any clues, other than generating a temp file, and then using

sqlcmd -E -i tempfile

which does work, but it's ugly.

3
  • try swapping quotes: echo 'print "tsql"' | sqlcmd -E
    – jftuga
    May 9, 2011 at 15:11
  • 1
    1) it's not a quoting problem, 2) your solution isn't valid TSQL, even if it was a quoting problem
    – Eric H.
    May 9, 2011 at 18:18
  • This simple command fails in what way? what is the error? "fails" is not a usable problem description. Sep 14, 2016 at 15:28

2 Answers 2

3

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
1
  • I needed to supply utf-8 data to sqlcmd. I used 'cmd //U //c ' to enable utf support across the pipe as well as solving the ReadTextLine issue.
    – codeDr
    Dec 1, 2015 at 20:20
2

I had similar problems working with SQLCMD in Bash and as of now this question is ranked third when searching for sqlcmd cygwin on Google. I too thought that it was due to line endings because of the error,

Sqlcmd: Error: Internal error at ReadTextLine (Reason: Unspecified error).

I tried various trickery such as process substitution but that didn't work. The best that I could come up with was using

sqlcmd -Q "print 'tsql'"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .