execute CMD command through JAVA

1

I'm having trouble running a command in CMD through JAVA. This command is executed by a .jar that is inside a directory "C: \ CopyUtility \ CopyUtility.jar." This is why I need to enter this directory and execute the command.

For this I am using the following Servlet below, which receives the parameters from a form on a .html page. I have already tested and the values are being sent correctly. I think the problem is running the command.

Public class ExecCopyTestPlanServlet extends HttpServlet {
    protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        //Search Request Parameters
        String strArea = request.getParameter("Area");
        String strID = request.getParameter("ID");
        String strTPID = request.getParameter("TPID");
        String strCommand = "java -jar RQMCopyUtility.jar" + strArea + strID + strTPID;


        Process exec;  
            try {  
                exec = Runtime.getRuntime().exec("cmd /C c:\CopyUtility"+ strCommand);
                if ( exec.waitFor() == 0)  
                    System.out.println("Executado.");  
                else  
                    System.out.println("ERRO");  
            } catch (IOException e) {  
                e.printStackTrace();  
            } catch (InterruptedException e) {  
                e.printStackTrace();  
        }  

    }
}

In this line I'm running the command:

exec = Runtime.getRuntime().exec("cmd /C c:\CopyUtility"+ strCommand);

But it is not working because the command does not run, it does not appear to be entering the directory "C: \ CopyUtility".

Is it necessary to open CMD.exe and leave the window open when the command is executed?

    
asked by anonymous 08.05.2017 / 01:40

0 answers