Question: How to use exec() command of Java to launch a batch file (the Syntax of using it)? How to use exec() command of Java to launch a batch file (the Syntax of using it). A piece of code will be usefull.\n\nThanks in advance

Answer: I'm not a java programmer, but this is what I came up with:\n\n\nimport java.util.*;\nimport java.io.*;\npublic class EXECBATCH\n{\n    public static void main(String args[])\n    {\n        try\n        {            \n            Runtime rt = Runtime.getRuntime();\n            Process proc = rt.exec("YOURBATCHFILEGOESHERE");\n            InputStream stderr = proc.getErrorStream();\n            InputStreamReader isr = new InputStreamReader(stderr);\n            BufferedReader br = new BufferedReader(isr);\n            String line = null;\n            System.out.println("<ERROR>");\n            while ( (line = br.readLine()) != null)\n                System.out.println(line);\n            System.out.println("</ERROR>");\n            int exitVal = proc.waitFor();\n            System.out.println("Process exitValue: " + exitVal);\n        } catch (Throwable t)\n          {\n            t.printStackTrace();\n          }\n    }\n}\n\nThere appear to be a number of potential "pitfalls" with using \nthe exec command.\nDepending on what your batch file does, you might run into some of them.\nI've linked to an article (where I got the above code from)  which discusses them, and their workarounds.
This question from the Yahoo Q&A forum is categorized in the topic: Education & Reference