how to get command output
843798Sep 21 2007 — edited Sep 23 2007Hello.
This is my first post here.
I want to run a bat file (windows xp) with Runtime and get the code the bat file returns.
When I launch the script from a console I get:
D:\Ejercicios_Oracle\BATCH_SCRIPTS>comando.bat @kk.sql
D:\Ejercicios_Oracle\BATCH_SCRIPTS>sqlplus -s fernando/sayaka@ferbd @kk.sql
declare
*+
ERROR en lÝnea 1:
ORA-01403: no se han encontrado datos
ORA-06512: en lÝnea 4
D:\Ejercicios_Oracle\BATCH_SCRIPTS>exit /B
And if I check the errorlevel I get:
D:\Ejercicios_Oracle\BATCH_SCRIPTS>echo %errorlevel%
+1403+
I have a little class that calls this bat file but I do not know how I could get the code 1403:
This is my class:
import java.lang.Runtime;
import java.lang.Process;
import java.io.IOException;
import java.lang.InterruptedException;
public class EjecutarProcesoSOreturn
+{+
+ public static int ejecuta(java.lang.String arg0, java.lang.String arg1)+
+ {+
+ java.lang.String[] args= new String[2];+
+ args[0]=arg0;+
+ args[1]=arg1;+
+ int ret = 0;+
+ System.out.println("En ejecuta");+
+ try+
+ {+
+ /* Se ejecta el comando utilizando el objeto Runtime+
+ y Process */+
+ Process p = Runtime.getRuntime().exec(args);+
+ try+
+ {+
+ /* Esperamos la finalizacion del proceso */+
+ ret = p.waitFor();+
+ //ret = p.exitValue();+
+ }+
+ catch (InterruptedException intexc)+
+ {+
+ System.out.println("Se ha interrumpido el waitFor: " + intexc.getMessage());+
+ ret = -1;+
+ }+
+ System.out.println("Codigo de retorno: "+ ret);+
+ }+
+ catch (IOException e)+
+ {+
+ System.out.println("IO Exception de exec : " + e.getMessage());+
+ e.printStackTrace();+
+ ret = -1;+
+ }+
+ finally+
+ {+
+ return ret;+
+ }+
+ }+
+ public static void main(java.lang.String[] args)+
+ {+
+ System.out.println("En main");+
+ System.out.println("args[0] " + args[0]);+
+ System.out.println("args[1] " + args[1]);+
+ ejecuta(args[0], args[1]);+
+ }+
+}+
When I run it I get:
D:\Ejercicios_Oracle\BATCH_SCRIPTS>java EjecutarProcesoSOreturn comando.bat @kk.sql
En main
args[0] comando.bat
args[1] @kk.sql
En ejecuta
Codigo de retorno: 0
And if I check the errorlevel I get:
D:\Ejercicios_Oracle\BATCH_SCRIPTS>echo %errorlevel%
+0+
How can I get the code 1403
returned from the class. I need it because this method is going to be used inside a program that must check the codes returned by the command.
Thanks in advance.