我正在将我的以下 bash 脚本迁移到 python
重击代码
sqlplus -S User/psw@inst << EOF
whenever sqlerror exit sql.sqlcode;
set echo off
set heading off
prompt *****************************
prompt *** Running Script 1***
@/my/location/Script1
prompt *****************************
prompt *** Running Script 2***
@/my/location/Script2
exit;
EOF
Python代码
(username, password, host) = ("user","psw","isntance")
conn_string = " %s/%s@%s "% (username,password,host)
#for script1
session = Popen(['sqlplus','-S', conn_string], stdin=PIPE, stdout=PIPE, stderr=PIPE)
sql_file = '%s/%s' % ('/my/folder', 'Script1.sql')
with open(sql_file) as f:
stdout, stderr = session.communicate(f.read())
print stdout
print stderr
#for script2
session = Popen(['sqlplus','-S', conn_string], stdin=PIPE, stdout=PIPE, stderr=PIPE)
sql_file = '%s/%s' % ('/my/folder', 'Script2.sql')
with open(sql_file) as f:
stdout, stderr = session.communicate(f.read())
print stdout
print stderr
我有两个问题,
1)有没有办法在不打开另一个实例的情况下运行两个脚本Popen
2)如何 prompt
在代码中实现功能python
?