我正在使用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') vs
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);。
发布于 2015-08-26 03:08:53
p.communicate()将根据子进程文档等待进程终止。除非您计划每次通信时终止并重新启动java进程,否则第二种方法(读/写)是唯一可用的方法。
https://stackoverflow.com/questions/32216622
复制相似问题