|
From: Ted H. <thu...@ro...> - 2004-07-17 19:14:31
|
Here is a self-contained and complete example of a JSP that execs a VB script. The VB script opens Excel, sleeps 4 seconds, quits Excel, then exits the script environment. On my Win2k server(s), this only works when JBoss is running standalone without the Java Service Wrapper. Could someone please try to reproduce my results? Thank you in advance. To install/run: 1) Copy VB script to C:\exectest.vbs 2) Install exectest.jsp to JBoss in your normal manner. --CUT HERE, FILE 1: exectest.vbs BEGIN--- Set objExcel = CreateObject( "Excel.Application" ) objExcel.DisplayAlerts = False objExcel.Visible = True WScript.Sleep 4000 objExcel.Quit WScript.Quit -- CUT HERE, FILE 2: exectest.jsp BEGIN-- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ page import="java.io.*,java.net.*,java.util.* " %> <html> <head> <title>Runtime.getRuntime().exec() Test</title> <%! public class StreamGobbler extends Thread { InputStream is; String type; OutputStream os; public StreamGobbler( InputStream is, String type ) { this( is, type, null ); } public StreamGobbler( InputStream is, String type, OutputStream redirect ) { this.is = is; this.type = type; this.os = redirect; } public void run() { try { PrintWriter pw = null; if( os != null ) pw = new PrintWriter(os); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line = null; while( (line = br.readLine()) != null ) { if( pw != null ) pw.println( line ); System.out.println( type + ")" + line ); } if( pw != null ) pw.flush(); } catch( IOException ioe ) { ioe.printStackTrace(); } } } %> <% String[] cmdArray = new String[2]; cmdArray[0] = "cscript"; cmdArray[1] = "C:\\exectest.vbs"; try { Process proc = Runtime.getRuntime().exec( cmdArray ) ; StreamGobbler errorGobbler = new StreamGobbler( proc.getErrorStream(), "ERR" ); StreamGobbler outputGobbler = new StreamGobbler( proc.getErrorStream(), "OUT" ); errorGobbler.start(); outputGobbler.start(); int exitVal = proc.waitFor(); out.println("Exit Value =" + exitVal ); } catch( Exception e ) { e.printStackTrace(); } %> </html> |