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

What happens when you run tsql -H production -U UsernameRemoved -P PasswordRemoved -p 1433 -I InstanceRemoved from the command line? (same question for printf, although I suspect that's not the problem)

Replies are listed 'Best First'.
Re^2: Trying to connect to MSSQL and return result. Script hangs indefinitely.
by Logic_Bomb421 (Novice) on Aug 06, 2014 at 19:01 UTC

    When running the normal tsql command, everything connects to MSSQL just fine. I've been reading into this more, and it appears I'd be better off using DBI to connect perl to a database. Does that sounds right to you?

      "just fine" is a little too vague, posting a sample command line session would be better.

      If the tsql you're using is this one: http://linux.die.net/man/1/tsql , then the problem is that it enters an interactive shell that you have to exit from, that's why it's hanging there (it's waiting for input). A quick Googling suggests that http://linux.die.net/man/1/bsqlodbc or http://linux.die.net/man/1/bsqldb might be better suited for your use case.

      If you're going to be running multiple queries on the database in one session, then yes, DBI is the way to go. However, for a single SELECT query run once every few minutes that just spits out a value, backticks are often an acceptable solution. A little better might be the capture function from IPC::System::Simple (that has better error handling), and IPC::Run even lets you set timeouts on external commands.