Note that there are some explanatory texts on larger screens.

plurals
  1. PObat file does not execute within Java
    text
    copied!<p>I have written some code for executing <code>.bat</code> file. which contains some commands like setting java <code>classpath,etc</code>..And finally there is one command which runs a Java class file.The H<code>elloWorld class</code> converts some xml file and generating a new xml file in some folder. When I double click .bat file, it executes fine, but when I try to run I am not getting any output as I was getting through double click the <code>.bat</code> file. How to make a batch execute and probably it would be nice if I could see the results through Java console. </p> <p>Following is MyJava code to execute the .bat file</p> <pre><code>public void run2() { try { String []commands = {"cmd.exe","/C","C:/MyWork/Java/classes/run.bat"} ; Process p = Runtime.getRuntime().exec(commands); BufferedReader in = new BufferedReader(new InputStreamReader( p.getInputStream())); String line = null; while ((line = in.readLine()) != null) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } } </code></pre> <p>And below the some commands which has been set to .bat file</p> <pre><code>set CLASSPATH=%CLASSPATH%;C:/MyWork/Java set CLASSPATH=%CLASSPATH%;C:/MyWork/Java/classes java -cp test.jar;test2.jar test.HelloWorld </code></pre> <p>Tried with <code>"/C"</code> commad as well. It does not execute. Actually it does not give effect of double click the <code>.bat</code> file. Is there any other way that I can try with?</p> <p>I can see the contents inside the <code>.bat</code> file through Eclipse console. But it does not give the desired output. Desired output means when I double click <code>.bat</code> file, it executes well. But through <code>java</code> call, I can see the contents only . </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload