I am trying to run SQL command using SQL file in python
process = subprocess.Popen(shlex.split(command), stdout=log)
print("command: {}".format(command))
print("split cmd: {}".format(shlex.split(command)))
This is the output on the console
Error occurred while opening or operating on file C: (Reason: Access is denied)
command: sqlcmd -i C:/Users/MyUser/Git/migrator/__logs__/logs-2024-05-20-105317235524-import/models/.build/scripts/import-Models-EF435017-123D-5CE9-9392-659C88AA2048.sql -S localhost
split cmd:['sqlcmd', '-i', 'C:/Users/MyUser/Git/migrator/__logs__/logs-2024-05-20-104845036741-import/models/.build/scripts/import-Models-EF435017-123D-5CE9-9392-659C88AA2048.sql', '-S', 'localhost']
- If I add double quotes to the file path and run it manually from the console it will work.
- If I remove the prefix
C:/Users/MyUser/Git/migrator/
it will also work without needing the double quotes,
(note that this prefix is where im running the python main file.) - Removing the prefix also works with python.
My script also works with postgres, so if I run my script the same way (using filename) but the command is postgres it also works.
Note: I checked there’s no whitespace in the filepath.
Note2: Im running this script on Windows.
My question is why does not it wotk with sqlcmd?
Thanks in advance.
I did try run it manually the command seems to work when running it from the console
New contributor
wanchaiS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.