Reputation: 791
I have a simple script, to call a sql script from python
subprocess.call([
'sqlcmd',
'-S', 'server_name',
'-d', 'db name'
'-i', r'path to the script + script name'
])
The python script runs without errors, but never calls the sql script. I can run the sql script through command line sqlcmd "path to the script + script name"
and it works as expected.
I can call a stored procedure using the subprocess
module with no problem,
subprocess.Popen([
'sqlcmd',
'-S', 'server_name',
'-d', 'db name'
'-Q', 'exec stored procedure'
])
but calling a separate script gives no results. I have tried including shell = True
or use Popen
but nothing changes.
To do more testing I have created a test script that just returns the name of the current database. I ran it through command line with no problems
sqlcmd -S server_name -d db_name -i "directory/test1.sql"
, getting the expected result. I have tried to run it with subprocess
module and got my issue again, I've tried subprocess.call_check
and got an error stating exit status 1
. So the script runs with command line, but doesn't with subprocess
module .
Upvotes: 0
Views: 219
Reputation: 791
My issue was with directories for sql script and the python script, even though I was specifying the full path for the sql script. They were on separate discs, and I was keep getting non-zero exit status 1
when I would use subprocess.call_check()
. I've put both scripts in the same location and the issue is gone.
Upvotes: 1