如何使用java servlet应用程序运行带有参数的.exe文件和.batch文件?

时间:2014-06-17 10:02:09

标签: java jsp batch-file servlets

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";
    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();
    }

0 个答案:

没有答案