I am trying to execute xmlaccess.bat file of web sphere Portal server uisng java but not getting any issue as well as no output but when i execute this bat file through command prompt,its working Fine..why it is ? dont'Know..please Help me out...

MyAPP :

public class BatchAPP {

    public static void main(String[] args) throws IOException, InterruptedException {

          Process  p = Runtime.getRuntime().exec("C:\\IBM\\WebSphere\\wp_profile\\PortalServer\\bin\\xmlaccess.bat -user admin -password admin -url http://localhost:10039/wps/config -in pageExport.xml -out result.xml");

         BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));

        String line;
        while ((line = input.readLine()) != null) {
            System.out.println(line);
        }

        input.close();
        int waitFor = p.waitFor();
         System.out.println("****Process****"  + waitFor);

    }

}

Command Is : xmlaccess.bat -user -password -url -in -out

That Bat File Reside in wHome/Portalserver/bin ----> If i run that application getting :

Exception in thread "main" java.io.IOException: Cannot run program "C:\IBM\WebSphere\wp_profile\PortalServer\bin\xmlaccess.bat": CreateProcess error=193, %1 is not a valid Win32 application

That's right, a bat file is not an application. The application that runs batch files from the command prompt is cmd.exe, so you need to execute something like
cmd /c mybatchfile.bat etc

ps from Java 5 onwards the preferred way to run Applications is via ProcessBuilder, not runtime exec.

also: never allow your main method to throw Exceptions.
you should understand why not long before you try to run more "advanced" applications like calling external applications.

Personally I don't see why main throwing execptions is a problem for non-production code
AFAIK, the JVM will call the main ThreadGroup's uncaughtException method, which (unless you installed your own handler) prints the exception's name and stacktrace. Not such a bad thing...

Thanks for Reply,i update code but still getting same issue

public class BatchAPP {

    public static void main(String[] args) throws IOException, InterruptedException {

        Process p = null;
        File batchFile = new File("C:\\IBM\\WebSphere\\wp_profile\\PortalServer\\bin\\xmlaccess.bat");
        String argument = "-user admin -password admin -url http://localhost:10039/wps/config -in pageExport.xml -out result.xml";

        ProcessBuilder processBuilder = new ProcessBuilder(batchFile.getAbsolutePath(), argument);
        processBuilder.redirectErrorStream(true);

        p = processBuilder.start();



        BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));

        String line;
        while ((line = input.readLine()) != null) {
            System.out.println(line);
        }

        input.close();
        int waitFor = p.waitFor();
        System.out.println("****Process****" + waitFor);

    }
}

Seems you missed this first time round...

That's right, a bat file is not an application. The application that runs batch files from the command prompt is cmd.exe, so you need to execute something like
cmd /c mybatchfile.bat etc

the problem with that is, that most who are used to put it in non-production code, sometimes by mistake put that non-production code into a production environment, simply out of habbit of writing the code like that.

Please tell me ,what i have to do

James already told you. re-read his last reply

Yeah Thanks both of You...I got it..:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.