exec command in java

2019-08-01 23:56发布

问题:

If i am using following command in java:

Process ps = Runtime.getRuntime().exec("some .exe file of VB");

How do I know that the particular .exe has done its job eg: it executed successfully.

How do i know that it has some error or just completed half task in java. How should I design my program in java to know or Is there any way to tell java from VB.

Any help is appreciated.

回答1:

I would assume that you could look at the exit status of the program: ps.exitValue() or you could read the stdout/stderr ps.getInputStream() / ps.getErrorStream() respectively.



回答2:

You get back a Process

http://download.oracle.com/docs/cd/E17476_01/javase/1.4.2/docs/api/java/lang/Process.html

Which has such methods as:

exitValue() 
getErrorStream() 
waitFor()

Which will get you what you need