【发布时间】:2019-06-15 22:19:11
【问题描述】:
需要以下代码的帮助 - 我想将三个列表的字符串元素作为输入传递给我在 python 脚本中调用的 java 程序。这是我到目前为止所做的 -
import subprocess
from subprocess import PIPE
from subprocess import Popen
amount = ['23.5', '12.5', '56.0', '176.1']
invoice_no = ['11290', '12892', '12802', '23489']
date = ['2/3/19', '12/30/17', '04/21/2018', '8/12/17', '12/21/18']
## problem is proc.communicate(). I am currently passing only invoice_no[i] as input.
for i in range (0, len(invoice_no)):
proc = subprocess.Popen(['java', '-jar', '/data/python/xyz.jar'],stdin=PIPE,stdout=PIPE, stderr=STDOUT)
q = proc.communicate(input = invoice_no[i])
print(q)
## But I want to pass amount and date as input as well.
## I dont know the syntax for that. I also want output as 1 or 0 i.e success or failure. Does anyone know syntax for this?
我看到的大多数问题都是将单个字符串作为输入传递。但这不是我想要的。即使是 subprocess 的官方文档也无助于找出如何传递多个输入语法。链接是-running java program from python script
How to execute java program using python considering inputs and outputs both
【问题讨论】:
-
不应该
-jar参数也应该是 Popen 的单独参数吗? -
不完全确定.. 我是 python 新手。在浏览了许多问题和文件后,我能够达到这一点。
标签: java python python-2.7 subprocess