0

I'm trying to launch an application from within an axis web service, but I can't understand what am I doing wrong. The class I used to generate the webservice is this:

public class Esecutore {

public String esegui(){ 
        try {

            ProcessBuilder builder=new ProcessBuilder("parser.bat");
            builder.redirectErrorStream(true);
            Process pr;
            pr = builder.start();
            InputStream stdout=pr.getInputStream();
            OutputStream stdin=pr.getOutputStream();
            BufferedReader br=new BufferedReader(new InputStreamReader(stdout));
            BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(stdin));
            String line = br.readLine();
            while(line!=null){
                line=br.readLine();
            }
            int termine=pr.waitFor();
            if(termine!=0){
                return "errore nell'inserimento";
            }
            return "finito";
        } catch (IOException e) {
            // TODO Auto-generated catch block
            return "errore: "+e.getMessage();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            return "errore: "+e.getMessage();
        }


}
}

the batch file works correctly when I execute it from the command line, and it just launches a .jar, which doesn't need any input. However, I can see that when I do it through this code it has an exit state different from 0, and since the .jar should write to a database I also know from the db logs it doesn't get executed at all.

Orgrim
  • 357
  • 1
  • 5
  • 13

1 Answers1

0

I would firstly test this class functionality outside axis to see if it works.
Since you have a 'bat' file, I assume we are talking about a batch file in Windows. And in this case, the ProcessBuilder should have in constructor "cmd /c start parse.bat". Please see here the complete explanations.

Community
  • 1
  • 1
Roxana
  • 1,569
  • 3
  • 24
  • 41