Java.io.IOException

hi every one

i have written tha following program but when i run it is showing

Java.io.IOException error=2

import java.util.*;

import java.io.*;

import java.lang.Runtime;

publicclass Sumprun{

publicvoid Sumprunnig()throws IOException{

try{

Runtime rt = Runtime.getRuntime();

Process proc = rt.exec("cd C:\\Program Files\\Sump");

Process proc1 = rt.exec("start sump.bat");

}

catch(Exception e){

System.out.println(e);

}

}

publicstaticvoid main(String args[]){

try{

Sumprun sump =new Sumprun();

sump.Sumprunnig();

}

catch(Exception e){

System.out.println(e);

}

}}

Message was edited by:

santhosh_thadvai

[1652 byte] By [santhosh_thadvaia] at [2007-11-27 0:25:07]
# 1

> Runtime rt = Runtime.getRuntime();

>Process proc = rt.exec("cd C:\\Program Files\\Sump");

>Process proc1 = rt.exec("start sump.bat");

hi,

try this instead:

Process proc = rt.exec("C:\\Program Files\\Sump\\sump.bat");

PS: the next time post the whole error message please

java_2006a at 2007-7-11 22:22:42 > top of Java-index,Java Essentials,Java Programming...
# 2
now also it is giving the same exceptionjava.io.IOException: CreateProcess: cd C:\Program Files\Sump\sump.bat error=2
santhosh_thadvaia at 2007-7-11 22:22:42 > top of Java-index,Java Essentials,Java Programming...
# 3
>java.io.IOException: CreateProcess: cd C:\Program >Files\Sump\sump.bat error=2remove the cd command, and try againuse e.printStackTrace(); instead of System.err.println(e); plz
java_2006a at 2007-7-11 22:22:42 > top of Java-index,Java Essentials,Java Programming...
# 4

the batch file is in the specified address so i have to go into that file and execute so i did tried by removing the " cd " but it siad that it could not find the specified file

so i added "cd" then i executed it now by putting the strack trace i got the following error

java.io.IOException: CreateProcess: cd C:\Program Files\Sump\sump.bat error=2

at java.lang.ProcessImpl.create(Native Method)

at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)

at java.lang.ProcessImpl.start(ProcessImpl.java:30)

at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)

at java.lang.Runtime.exec(Runtime.java:591)

at java.lang.Runtime.exec(Runtime.java:429)

at java.lang.Runtime.exec(Runtime.java:326)

at Sumprun.Sumprunnig(Sumprun.java:12)

at Sumprun.main(Sumprun.java:24)

Press any key to continue . . .

Message was edited by:

santhosh_thadvai

santhosh_thadvaia at 2007-7-11 22:22:42 > top of Java-index,Java Essentials,Java Programming...
# 5

I made the following test:

1- create simple bat file C:\Program Files\test.bat that contains:

echo 'hello'

2-execute this external program as follows:

import java.io.BufferedReader;

import java.io.InputStreamReader;

public class ExecuteCommand {

/**

* @param args

*/

public static void main(String[] args) {

try {

Process p = Runtime.getRuntime().exec("C:\\Program Files\\test.bat");

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

String line;

while ((line = input.readLine()) != null) {

System.out.println(line);

}

input.close();

} catch (Exception e) {

e.printStackTrace();

}

}

}

results:

'hello'

java_2006a at 2007-7-11 22:22:42 > top of Java-index,Java Essentials,Java Programming...
# 6

i have tried what you have told for the sump.bat file now it is giving the error that

windows cannot find 'jre5\bin\javaw' make sure you have typed the name correctly or try the manual search

what doesit mean?

but while i am trying to manually execute at the command prompt

by going to the directory of Sump then

c:\programe files \sump>sump.bat

the sump application is opening.

santhosh_thadvaia at 2007-7-11 22:22:42 > top of Java-index,Java Essentials,Java Programming...