Код: Выделить всё
import os
# Specify the directory you want to change to, take input from keyboard
directory_path = r"C:\code\xyz\deployment\tbd\example"
# Change the directory
os.chdir(directory_path)
затем я запускаю простую функцию подпроцесса
Код: Выделить всё
def execute_sqlplus_command(command):
"""Executes a SQL*Plus command and returns the output."""
session = subprocess.Popen(
["sqlplus", "-S", "test/password@database"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
sql_command = command.encode() + b";\n"
stdout, stderr = session.communicate(sql_command)
return stdout.decode(), stderr.decode()
Код: Выделить всё
# calls for running script
command = "set role lsdba;"
output, error = execute_sqlplus_command(command)
command = r"@lsdba.sql;"
output, error = execute_sqlplus_command(command)
Код: Выделить всё
Output: SP2-0310: unable to open file "lsdba.sql;"
- Запуск "@lsdba.sql;" в sqlplus работает нормально и работает.
- Я попробовал указать более конкретный путь к конкретной папке, но она не открывается.
- Я проверил и изменил конфиденциальность настройки в файл sql.
Я делаю что-то не так в скрипте Python?
Подробнее здесь: https://stackoverflow.com/questions/792 ... r-sp2-0310