getRuntime().exec problem in win2000

S

sanjay

Hi,

Im trying to execute a batch file using following codes, but it just
opens a dos window and quickly closes it.

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("c:\\usr\\a.bat");
// also tried like rt.exec("cmd /c c:\\usr\\a.bat");

InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);

int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
System.out.println("Process error: " + stderr);

I did get the expected bat file result and getting below output.

Process exitValue: 1
Process error: java.io.FileInputStream@5d351325

Anyone know why !!

Thanks,
Sanjay
 
N

nos

i would like to guess
first the 1 is standard for true or ok or whatever in 'c' land
it might be the return code of the last process in your bat file
second it looks like the value printed
is the standard format for a reference to an object
it might be the reference to stderr
 
A

Andy Fish

in my experience you must have an 'exit' statement in the bat file. if you
just drop off the end, it won't return the status to the caller

of course this then means you can't run the bat file from a command line
because it will close your command window afterwards

dontya just love windows
 
N

nos

you must not have used "command prompt"
or even DOS for that matter for a long time
i think there is always a return status even if it is never set
also, the window doesn't close unless you execute
the batch file by clicking on an icon, it stays open
if you execute it via command
 
X

Xu

sanjay said:
Hi,

Im trying to execute a batch file using following codes, but it just
opens a dos window and quickly closes it.

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("c:\\usr\\a.bat");
// also tried like rt.exec("cmd /c c:\\usr\\a.bat");

InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);

int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
System.out.println("Process error: " + stderr);

I did get the expected bat file result and getting below output.

Process exitValue: 1
Process error: java.io.FileInputStream@5d351325

Anyone know why !!

Thanks,
Sanjay
try
Process proc = rt.exec("start c:\\usr\\a.bat");

otherwise you need to use a dos window to execute your java program, so
that i wont close the current dos window.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top