【问题标题】:results not print Python - SQlplus结果不打印 Python - SQlplus
【发布时间】:2013-07-08 01:44:21
【问题描述】:

我写了下面的代码在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()

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

【问题讨论】:

    标签: python python-2.7 sqlplus


    【解决方案1】:

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

    (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
    

    【讨论】:

      猜你喜欢
      • 2019-03-11
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      • 2016-03-08
      • 2019-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多