0

我编写了以下代码来在 sqlplus 中运行脚本

(username, password, host) = ("user","psw","isntance") 
conn_string = " %s/%s@%s "% (username,password,host)
session = Popen(['sqlplus','-S', conn_string], stdin=PIPE, stdout=PIPE, stderr=PIPE)
sql_file = '%s/%s' % ('/my/folder', 'File.sql')
f= open(sql_file,'r')
cmd = f.read()
session.stdin.write(cmd)
stdout, stderr = session.communicate()

代码执行没有任何错误。但我没有看到任何结果被打印出来。不确定我哪里出错了。

4

1 回答 1

0

您的代码没有打印语句。试试下面的代码:

(username, password, host) = ("user","psw","isntance") 
conn_string = " %s/%s@%s "% (username,password,host)
session = Popen(['sqlplus','-S', conn_string], stdin=PIPE, stdout=PIPE, stderr=PIPE)
sql_file = '%s/%s' % ('/my/folder', 'File.sql')
with open(sql_file) as f:
    stdout, stderr = session.communicate(f.read())
print 'output: %s' % stdout
print 'error: %s' % stderr
于 2013-07-08T03:31:59.630 回答