in reply to Trying to connect to MSSQL and return result. Script hangs indefinitely.

I suspect it is the "%b" that you are attempting to pass to "printf", but is getting eaten by perl interpolation.

Try this to reproduce the issue:

perl -e 'print qx|printf "%b" "this is a q\'uot\'ed test|'
UPDATE:

More likely, each single quote used inside the backticks needs to be double-single quoted replaced by the sequence '"'"' , to escape it.

UPDATE 2:

In the previous example, the backslashes are useless. To produce single quotes in the output, the following works (on Linux (SLES). The O.P had hints that although he's using MSSQL, the binaries (e.g. /usr/bin/printf) point to Linux):

perl -e 'print qx|echo "%b" "this is a qu'"'"'oted'\'' test"|,"\n"'
Note - that the slightly shorter alternate replacement for a single quote '\'' used above also works.

        Profanity is the one language all programmers know best.

Replies are listed 'Best First'.
Re^2: Trying to connect to MSSQL and return result. Script hangs indefinitely.
by Anonymous Monk on Aug 06, 2014 at 21:23 UTC
    Maybe I'm missing something: How would incorrect quoting cause Perl to hang? Trying bad quoting on qx I get "sh: Syntax error: Unterminated quoted string". Are there shells that hang on bad quoting?
      My bash shell on SLES( 2.6.32.12-0.7-default #1 SMP 2010-05-20 11:14:20 +0200 x86_64 x86_64 x86_64 GNU/Linux) hangs on the first code sample, waiting for the close single quote.

      After one is provided, it complains (and perl does too .. the intent was to show code that appears to hang in the shell). Here is the session:

      />: perl -e 'print qx|printf "%b" "this is a q\'uot\'ed test|' > > .. Hanging here > .. until quote.. > ' -bash: .. Hanging here .. until quote.. : command not found Can't find string terminator "|" anywhere before EOF at -e line 1. />:

              Profanity is the one language all programmers know best.

        Hm, same here, although it's bash that's hanging waiting for input, not Perl or the backticks, as in the OP.

        $ perl -wMstrict print qx|printf "%b" "this is a q\'uot\'ed test"|, "\n"; print qx|printf "%b" "this is a q\'uot\'ed test|; print qx|printf "%b" "this is a q\'uot'ed test|; __END__ this is a q'uot'ed test sh: Syntax error: Unterminated quoted string sh: Syntax error: Unterminated quoted string