如何执行批处理文件& .exe文件使用jsp servlet?

时间:2014-06-23 06:13:13

标签: java jsp servlets

我正在FASTA format为爆炸提供输入。之后我想在我的项目文件夹中创建sequence.FASTA文件。我想执行批处理文件,参数为blastp.exe文件,sequence.FASTA文件,数据库文件,输出文件。

sequence.FASTA

的文件创建没有问题
 ERROR IN: the batch file is not execute, So the I am not able to get the output file for display.

ERROR is : java.io.FileNotFoundException: D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp4\wtpwebapps\toxin-data\outputprotein.txt (The system cannot find the file specified)

我有以下代码:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String values=request.getParameter("t1");

ServletContext servletContext = request.getSession().getServletContext();
servletContext = request.getSession().getServletContext();
String path="//sequence.FASTA"; /*file is created in getRealPath()*/
String uploadFile=servletContext.getRealPath(path);

File outputFile = new File(uploadFile);
FileWriter fout = new FileWriter(outputFile);
fout.write(values);
fout.close();

servletContext = request.getSession().getServletContext();
String blastPath="//blast.bat";
String blastBat_path=servletContext.getRealPath(blastPath);
Process process = new ProcessBuilder(blastBat_path).start();
try {
    process.waitFor();
} catch (InterruptedException e) {e.printStackTrace();} 
    process.destroy();

    /* to read output file for display */
    BufferedReader br1=null;
    br1= new BufferedReader(new FileReader(servletContext.getRealPath("//outputprotein.txt")));
    try {
        StringBuilder sb = new StringBuilder();
        String line1 = br1.readLine();

        while (line1 != null)  {
            sb.append(line1);
            sb.append(System.lineSeparator());
            line1 = br1.readLine();
        }
        String everything = sb.toString();
        out.println("<pre>"+everything+"</pre>");
    } finally {
        br1.close();
    } 
    fout.close();
}

此处getRealpath()为:

  

d:\ workspace.metadata.plugins \ org.eclipse.wst.server.core \ TMP4 \ wtpwebapps \毒素数据

0 个答案:

没有答案