Executando *.exe

Pessoal,

Estou fazerndo um método para executar um arquivo.

Vejam se está correto o que estou fazendo:


private void gifGenerator(Long[] logosId) throws SQLException, IOException {
         
         try {
         
             DAO bannerDAO = DAOFactory.getDAOInstance(DAOFactory.BANNER_DAO);
             String[] logoListDirName = null;

             ResourceBundle bundle = ResourceBundle.getBundle("br.com.teste.www.dmd.aplic_config");
             String gifGeneratorPath = bundle.getString("gifgenerator.path");

             System.out.println("gifGeneratorPath: "+gifGeneratorPath);

             File gifGenerator = new File(new File(gifGeneratorPath).getParent(), "GifGenerator.exe");
         
             if(gifGenerator.exists()) {

                 String[] cmd = new String[50];
                 cmd[0] = gifGenerator.getAbsolutePath();
                 cmd[1] = " -t 1000ms";
                 cmd[2] = " -r 1";

                 int k = 0;

                 for(int j = 0; j < logosId.length; j++) {                

                     logoListDirName = new String[logosId.length];
                     System.out.println("logosId[j]: "+logosId[j]);
                     Banner b = (Banner) bannerDAO.getObject(logosId[j]);                            
                     System.out.println("b.getBannerFile(): "+b.getBannerFile());
                     logoListDirName[j] = b.getBannerFile().toString();  
                     System.out.println("logoListDirName[j]: "+logoListDirName[j]); 
                     cmd[3] = " -f";
                     cmd[j+4] = " "+logoListDirName[j]+";";
                     k = j+5;


                 }  

                 cmd[k] = " -o logos.gif";

                 //System.out.print("comando: "+cmd[0]+cmd[1]+cmd[2]+cmd[3]+cmd[4]+cmd[5]+cmd[6]+cmd[7]+cmd[8]+cmd[9]);

                 final Process fp = Runtime.getRuntime().exec(cmd);
                 new Thread() {
                    {
                        this.setDaemon(true);
                    }

                    
                }.start();
                
                } else {
                //Log.warning("@PresentationRecorder#removeRMEventsFromFile(): rmevents.exe not found!");
            }
        } catch(Exception e) {
            //Log.warning("Exception while trying to remove events from file", e);
        }
        
         
     }

Aquele print do comando está assim:
comando: C:\Documents and Settings\vlima\Desktop\teste\apache-tomcat-5.5.20\weba
pps\business\WEB-INF\GifGenerator.exe -t 1000ms -r 1 -f D:\helix_data\dmdweb\ban
ners\cpqdlogo200_20070214104725876.jpg; D:\helix_data\dmdweb\banners\logo_cremes
p_20070214104755688.jpg; -o logos.gif

se eu fizer isso nmo terminal funciona.

Agora no java, falta eu fazer alguma coisa, pq não está gerando o arquivo logos.gif.

Obrigado.

Pessoal,

tem algo errado aqui:


private void gifGenerator1(Long[] logosId, long id) throws SQLException, IOException {
         
         try {
         
             DAO bannerDAO = DAOFactory.getDAOInstance(DAOFactory.BANNER_DAO);
             
             ClientDAO cDAO = (ClientDAO) DAOFactory.getDAOInstance(DAOFactory.CLIENT_DAO);
             ClientFilter clientFilter = new ClientFilter();
             clientFilter.setId(id);
             Client c = null;            
             List clientList;
             try {
                 clientList = cDAO.searchObjects(clientFilter);
                 for (int i = 0; i < clientList.size(); i++) {
                     c = (Client) clientList.get(i);
                 }
             } catch (IllegalArgumentException e1) {
                 // TODO Auto-generated catch block
                 e1.printStackTrace();
             } catch (SQLException e1) {
                 // TODO Auto-generated catch block
                 e1.printStackTrace();
             }
             
             String[] logoListDirName = null;

             ResourceBundle bundle = ResourceBundle.getBundle("br.com.teste.www.dmd.aplic_config");
             String gifGeneratorPath = bundle.getString("gifgenerator.path");             
             String rootDir = bundle.getString("rootDir.directory");

             System.out.println("gifGeneratorPath: "+gifGeneratorPath);

             File gifGenerator = new File(new File(gifGeneratorPath).getParent(), "GifGenerator.exe");
         
             if(gifGenerator.exists()) {

                 String[] cmd = new String[50];
                 cmd[0] = gifGenerator.getAbsolutePath();
                 cmd[1] = " -t 1000";
                 cmd[2] = " -r 1";

                 int k = 0;

                 for(int j = 0; j < logosId.length; j++) {                

                     logoListDirName = new String[logosId.length];
                     System.out.println("logosId[j]: "+logosId[j]);
                     Banner b = (Banner) bannerDAO.getObject(logosId[j]);                            
                     System.out.println("b.getBannerFile(): "+b.getBannerFile());
                     logoListDirName[j] = b.getBannerFile().toString();  
                     System.out.println("logoListDirName[j]: "+logoListDirName[j]); 
                     cmd[3] = " -f ";
                     if(j == (logosId.length -  1)) {
                         cmd[j+4] = logoListDirName[j];
                     } else {
                         cmd[j+4] = logoListDirName[j]+";";
                     }                     
                     k = j+5;


                 }  
                 
                 String logos = rootDir + File.separator + c.getLink() +  File.separator + "logos.gif";

                 cmd[k] = " -o "+logos;

                 System.out.print("comando: "+cmd[0]+cmd[1]+cmd[2]+cmd[3]+cmd[4]+cmd[5]+cmd[6]);
                 
                 Runtime.getRuntime().exec(cmd);

                 } else {
                //Log.warning("@PresentationRecorder#removeRMEventsFromFile(): rmevents.exe not found!");
            }
        } catch(Exception e) {
            //Log.warning("Exception while trying to remove events from file", e);
        }
        
         
     }

no terminal o comando funciona, mas quanto tento pelo java não.

comando: C:\Documents and Settings\vlima\Desktop\teste\apache-tomcat-5.5.20\weba
pps\business\WEB-INF\GifGenerator.exe -t 1000 -r 1 -f D:\helix_data\dmdweb\banne
rs\moonwalk_20070301134957182.gif;D:\helix_data\dmdweb\banners\footprint_2007030
1135004104.gif -o C:\Documents and Settings\vlima\Desktop\teste\apache-tomcat-5.
5.20\webapps\ROOT\testando\logos.gif

Obrigado.

Está dando esse erro:

comando: C:\Documents and Settings\vlima\Desktop\teste\apache-tomcat-5.5.20\weba
pps\business\WEB-INF\GifGenerator.exe -t 1000 -r 1 -f D:\helix_data\dmdweb\banne
rs\moonwalk_20070301134957182.gif;D:\helix_data\dmdweb\banners\footprint_2007030
1135004104.gif -o C:\Documents and Settings\vlima\Desktop\teste\apache-tomcat-5.
5.20\webapps\ROOT\testando\logos.gif1java.lang.NullPointerException
at java.lang.ProcessBuilder.start(ProcessBuilder.java:441)
at java.lang.Runtime.exec(Runtime.java:591)
at java.lang.Runtime.exec(Runtime.java:464)
at br.com.teste.www.dmd.comm.ChatServlet.gifGenerator(ChatServlet.java:33
02)
at br.com.teste.www.dmd.comm.ChatServlet.processRequest(ChatServlet.java:
454)
at br.com.teste.www.dmd.comm.ChatServlet.doPost(ChatServlet.java:2808)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:432)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)
at java.lang.Thread.run(Thread.java:595)

Olha, eu nem sei o que vc tentou fazer, pode ser que eu esteja falando besteira…

Mas o comando: Runtime.getRuntime().exec(cmd);
que eu saiba ele só espera um nome de um executável, então acho q ele não deve aceitar os outros

se fosse só assim ele funcionaria

Runtime.getRuntime().exec(“C:\Documents and Settings\vlima\Desktop\teste\apache-tomcat-5.5.20\weba
pps\business\WEB-INF\GifGenerator.exe”);

Caso todo o endereço estivesse certo…