【发布时间】:2015-11-19 21:39:40
【问题描述】:
我正在使用 java 引擎来处理一些内容。
我想知道它会占用这样不必要的资源。
command = 'some command to run my jar file'
p = subprocess.Popen(command, stdout = subprocess.PIPE, stdin = subprocess.PIPE)
比较
output,err = p.communicate('some string that is passed to the java jar')
对
p.stdin.write('some string that is passed to the java jar \n')
p.stdin.flush()
output = p.stdout.readline()
为问题提供一些背景信息。字符串是动态生成的,因此我不想打开和关闭 java 应用程序,所有字符串都是生成的。
例如:
我的python引擎创建了一个字符串
'Hi i am going home now' 传递给java引擎运行并获取输出。
接下来它会产生“He is going home now”并重复该过程。
显然java程序写到System.out.println(output);
【问题讨论】:
标签: java python subprocess