无法从cgi运行Java命令 [英] unable to run java command from cgi

查看:154
本文介绍了无法从cgi运行Java命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有在Linux上使用tika读取文档文件的功能:

I have this function to read a doc file using tika on linux:

def read_doc(doc_path):
    output_path=doc_path+'.txt'
    java_path='/home/jdk1.7.0_17/jre/bin/'
    environ = os.environ.copy()
    environ['JAVA_HOME'] =java_path
    environ['PATH'] =java_path
    tika_path=java_path+'tika-app-1.3.jar'
    shell_command='java -jar %s --text --encoding=utf-8 "%s" >"%s"'%(tika_path,doc_path,output_path)
    proc=subprocess.Popen(shell_command,shell=True, env=environ,cwd=java_path)
    proc.wait()

当我从命令行运行该函数时,它运行良好,但是当我使用CGI调用同一函数时,出现以下错误:

This function works fine when I run it from the command line, but when I call the same function using CGI, I get the following error:

VM初始化期间发生错误,无法保留足够的空间 对象堆空间

Error occurred during initialization of VM Could not reserve enough space for object heap

我检查了先前针对此特定错误的答案,他们建议增加内存,但这似乎不起作用...我认为这与内存分配无关,而是一些读/写/执行来自cgi脚本的特权,您知道如何解决此问题吗?

I checked previous answers for this particular error and they suggest increasing the memory, but this doesn't seem to work...I don't think this has to do with memory allocation, but rather some read/write/execute privilages from the cgi script, any idea how to solve this problem?

推荐答案

您要在内存中加载整个JVM实例&每个CGI调用的处理空间.那很糟.很坏.用于性能和内存使用.增加内存分配是无法解决真正问题的黑客.绝对不应通过CGI调用核心Java代码.

You're loading an entire JVM instance within the memory & process space of each individual CGI invocation. That's bad. Very bad. For both performance and memory usage. Increasing memory allocation is a hack that doesn't address the real problem. Core java code should almost never be invoked via CGI.

您会过得更好:

  • 通过在Web服务器中运行Java Servlet来避免CGI和Python,该Java Servlet使用所需的参数直接调用相应的Tika类.将用户URL直接映射到Servlet(通过Servlet类上的@WebServlet("someURL")批注).
  • 在服务器模式下运行Tika 并通过REST通过REST调用Python.
  • 作为服务器/守护进程分别运行一个核心Java应用程序,让它在TCP ServerSocket上侦听.通过客户端套接字从Python调用.
  • Avoiding both CGI and Python by running a java Servlet within your web server that invokes the appropriate Tika class directly with desired arguments. Map the user url directly to the servlet (via @WebServlet("someURL") annotation on the Servlet class).
  • Running Tika in server mode and invoking it via REST from Python.
  • Running a core java app separately as a server/daemon proces, have it listen on a TCP ServerSocket. Invoke from Python via a client socket.

这篇关于无法从cgi运行Java命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆