SQLCMD hanging

  • Hi All

    I have a php exec command which runs SQLCMD as follows the sqlcmd command works by itself but when i run it in php it hangs, any ideas

    exec('c:\WINDOWS\system32\cmd.exe /c START C:\inetpub\wwwroot\batchfiles\export.bat');

    this runs a sqlcmd batch file as follows

    sqlcmd -S d3licsql02 -d TestData -U sa -P sqldba -Q "select * from dbo.newtable" -s "," -o "C:\inetpub\wwwroot\cleansed\result.csv"

  • Oracle765 (6/27/2013)


    Hi All

    I have a php exec command which runs SQLCMD as follows the sqlcmd command works by itself but when i run it in php it hangs, any ideas

    exec('c:\WINDOWS\system32\cmd.exe /c START C:\inetpub\wwwroot\batchfiles\export.bat');

    this runs a sqlcmd batch file as follows

    sqlcmd -S d3licsql02 -d TestData -U sa -P sqldba -Q "select * from dbo.newtable" -s "," -o "C:\inetpub\wwwroot\cleansed\result.csv"

    It could be lots of things.

    A couple comments:

    1. Please tell me this just your testbed your taking this code from. Do not use the sa Login for application access. Ideally the Login should be disabled on the instance. Use Windows Authentication if possible. Either way, Windows Authentication or SQL Authentication, the Login only needs to be connected to a User in TestData with SELECT permissions on dbo.newtable.

    2. Does the Account running your website have permission to access cmd.exe and to write to your output location?

    I would creqte a new bat file next to your current one that just uses echo to pipe into a new file some data at your output location. Just to make sure your website can use cmd.exe and that it can write to your output location.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • hi there thanks for your reply and yes it is the testbed, also it is still creating the file which happens very quick, but why it hangs i am not sure

  • I am thinking this might be a PHP problem. From the EXEC() documentation:

    Note:

    If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

    cmd.exe /C should exit but PHP may be looking to have the output redirected before it will return control. I am guessing here, but maybe you could supplying the second argument to the EXEC function to capture the output from the call.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply