<legend id='9k9QT'><style id='9k9QT'><dir id='9k9QT'><q id='9k9QT'></q></dir></style></legend>

    1. <i id='9k9QT'><tr id='9k9QT'><dt id='9k9QT'><q id='9k9QT'><span id='9k9QT'><b id='9k9QT'><form id='9k9QT'><ins id='9k9QT'></ins><ul id='9k9QT'></ul><sub id='9k9QT'></sub></form><legend id='9k9QT'></legend><bdo id='9k9QT'><pre id='9k9QT'><center id='9k9QT'></center></pre></bdo></b><th id='9k9QT'></th></span></q></dt></tr></i><div id='9k9QT'><tfoot id='9k9QT'></tfoot><dl id='9k9QT'><fieldset id='9k9QT'></fieldset></dl></div>
      <tfoot id='9k9QT'></tfoot>

          <bdo id='9k9QT'></bdo><ul id='9k9QT'></ul>

        <small id='9k9QT'></small><noframes id='9k9QT'>

      1. 如何在 python 代码中获取 .jar 执行的输出?

        How to get the output from .jar execution in python codes?(如何在 python 代码中获取 .jar 执行的输出?)

          • <i id='PuH4k'><tr id='PuH4k'><dt id='PuH4k'><q id='PuH4k'><span id='PuH4k'><b id='PuH4k'><form id='PuH4k'><ins id='PuH4k'></ins><ul id='PuH4k'></ul><sub id='PuH4k'></sub></form><legend id='PuH4k'></legend><bdo id='PuH4k'><pre id='PuH4k'><center id='PuH4k'></center></pre></bdo></b><th id='PuH4k'></th></span></q></dt></tr></i><div id='PuH4k'><tfoot id='PuH4k'></tfoot><dl id='PuH4k'><fieldset id='PuH4k'></fieldset></dl></div>
              <tfoot id='PuH4k'></tfoot>

            • <small id='PuH4k'></small><noframes id='PuH4k'>

                <tbody id='PuH4k'></tbody>

                <legend id='PuH4k'><style id='PuH4k'><dir id='PuH4k'><q id='PuH4k'></q></dir></style></legend>
                  <bdo id='PuH4k'></bdo><ul id='PuH4k'></ul>
                  本文介绍了如何在 python 代码中获取 .jar 执行的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在编写 python 模块,该模块执行 SQL 到 DBMS 并检索数据.我正在尝试使用 jdbc jar 文件而不是本机 DB 驱动程序.我想知道如何在 python 中执行 jar 文件并从 jar 执行中获取输出.而且我想知道如何将 SQL 字符串传递给 jar 参数.这是简化的代码.非常感谢任何帮助.

                  I'm programming the python module that executes SQL to DBMS and retrieves data. I'm trying to use jdbc jar files instead of native DB drivers. I'm wondering how to executes jar file in python and get output from jar execution. And I'd like to know how to pass SQL string to jar argument. Here is the simplified code. Any help is greatly appreciated.

                  [java代码]

                  public class GetDBResults {
                      public static void main(String[] args) {
                  
                          // return sql results
                          for(int i=0; i<=100; i++){
                              // Is this the proper way to generate the output?
                              System.out.println(i+"/t"+i*100+1);
                      }
                    }
                  }
                  

                  [python代码]

                  subprocess.call( [ 'java','-jar','./GET_DB_DATA.jar' )
                  
                  # how to get results from jar execution?
                  # how to pass SQL string to jar execution?
                  

                  推荐答案

                  可以通过管道读取输出:

                  You can read the output through pipe:

                  >>> from subprocess import Popen, PIPE, STDOUT
                  >>> p = Popen(['java', '-jar', './GET_DB_DATA.jar'], stdout=PIPE, stderr=STDOUT)
                  >>> for line in p.stdout:
                      print line
                  

                  关于将字符串传递给标准输入,可以这样实现:

                  As regards passing string to stdin, you can achieve it this way:

                  >>> p = Popen(['cat'], stdin=PIPE, stdout=PIPE, stderr=STDOUT)
                  >>> stdout, stderr = p.communicate(input='passed_string')
                  >>> print stdout
                  passed_string
                  

                  这篇关于如何在 python 代码中获取 .jar 执行的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                      <tbody id='LLWl3'></tbody>
                    <i id='LLWl3'><tr id='LLWl3'><dt id='LLWl3'><q id='LLWl3'><span id='LLWl3'><b id='LLWl3'><form id='LLWl3'><ins id='LLWl3'></ins><ul id='LLWl3'></ul><sub id='LLWl3'></sub></form><legend id='LLWl3'></legend><bdo id='LLWl3'><pre id='LLWl3'><center id='LLWl3'></center></pre></bdo></b><th id='LLWl3'></th></span></q></dt></tr></i><div id='LLWl3'><tfoot id='LLWl3'></tfoot><dl id='LLWl3'><fieldset id='LLWl3'></fieldset></dl></div>

                      <legend id='LLWl3'><style id='LLWl3'><dir id='LLWl3'><q id='LLWl3'></q></dir></style></legend>
                    1. <tfoot id='LLWl3'></tfoot>

                          <bdo id='LLWl3'></bdo><ul id='LLWl3'></ul>
                        • <small id='LLWl3'></small><noframes id='LLWl3'>