Как выполнить пакетный файл и .exe-файл с помощью jsp сервлета?

#java #jsp #servlets

#java #jsp #сервлеты

Вопрос:

Я даю ввод для blast в FASTA format . После этого я хочу создать sequence.FASTA файл в папке моего проекта. И я хочу выполнить пакетный файл с параметрами в виде blastp.exe файла, sequence.FASTA файла, файлов базы данных, выходного файла.

При создании последовательности файлов проблем нет.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.pluginsorg.eclipse.wst.server.coretmp4wtpwebappstoxin-dataoutputprotein.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.pluginsorg.eclipse.wst.server.coretmp4wtpwebappstoxin-data

Комментарии:

1. Вы уверены, что файл находится там, где вы пытаетесь его выполнить.

2. Вы говорите getRealPath() , что дает вам ......tmp4wtpwebappspublic_html , и у вас есть вызов servletContext.getRealPath("//outputprotein.txt") . Но в то же время у вас появляется сообщение об ошибке, в котором говорится, что он не может найти файл ......tmp4wtpwebappstoxin-dataoutputprotein.txt . Эти каталоги не совпадают, вы действительно уверены, что файл находится там, где думает ваш сервлет?

3. Речь s not about outputprotein.txt. It идет о файле blast.batch, который не выполняется для создания outputprotein.txt досье.

4. я. файл находится в той же папке для выполнения