I am trying to execute sql code in sqlcmd through subprocess. The "-i" option of sqlcmd expects a file. I am converting the sql code into file stream with StringIO and passing it as a argument to popen, but it fails
import subprocess
from subprocess import Popen
from io import StringIO
sql="select @@version" ## huge sql
["sqlcmd","-s","sql_SERVER","-i","StringIO(sql)"]
p = Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
output, errors = p.communicate()
I get the below error
sshProcess = subprocess.Popen(argv, shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True,bufsize=-1,encoding='latin1')
File "/home/mafiree/.pyenv/versions/3.8.0/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/home/mafiree/.pyenv/versions/3.8.0/lib/python3.8/subprocess.py", line 1637, in _execute_child
self.pid = _posixsubprocess.fork_exec(
TypeError: expected str, bytes or os.PathLike object, not _io.StringIO