- From: Moedl Raimund <Raimund.Moedl@oen.siemens.de>
- Date: Mon, 8 Jun 1998 13:36:56 +0200
- To: "'www-jigsaw@w3.org'" <www-jigsaw@w3.org>
Hello, I want to do an exec( "bash..." ) from a servlet. But it works only standalone, with the correct output <HTML><HEAD><TITLE>UDC</TITLE></HEAD> <pre> Mon Jun 08 11:25:08 GMT 1998 Hello! (from .sh) waiting... status: 0 </pre> </HTML> The servlet sends this to the browser: <HTML><HEAD><TITLE>UDC</TITLE></HEAD> <pre> Mon Jun 08 11:19:25 GMT 1998 waiting... status: 127 </pre> </HTML> Has someone an idea where this strange behaviour could come from ? Raimund ------------------------------------------------------------------------ ------------------- import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.Date; import java.util.Enumeration; public class MyCGI extends HttpServlet { public void init( ServletConfig conf ) throws ServletException { super.init( conf ); } public void doGet( HttpServletRequest req, HttpServletResponse res ) throws IOException { res.setContentType( "text/html" ); PrintWriter out = res.getWriter(); print( out ); } private static void print( PrintWriter out ) { out.println( "<HTML><HEAD><TITLE>UDC</TITLE></HEAD>" ); out.println( "<pre>" ); try { out.println( new Date().toString() ); Runtime rt = Runtime.getRuntime(); // ********** Works only through main(). // ********** Fails within servlet. (status=127) Process proc = rt.exec( "c:\\Cygnus\\B19\\H-i386-cygwin32\\bin\\bash -c //h/udc/myscript.sh" ); // ********** Works. //Process proc = rt.exec( "c:\\Cygnus\\B19\\H-i386-cygwin32\\bin\\cat //h/udc/myscript.sh" ); //Process proc = rt.exec( "c:\\Cygnus\\B19\\H-i386-cygwin32\\bin\\ls -al //h/udc/myscript.sh" ); InputStream in = proc.getInputStream(); BufferedReader br = new BufferedReader( new InputStreamReader( in ) ); String line; while( (line = br.readLine()) != null ) { out.println( line ); } br.close(); out.println( "waiting..." ); int status = proc.waitFor(); out.println( "status: " + status ); } catch( Throwable e ) { out.println( "*** unexpected ***" ); e.printStackTrace( out ); } out.println( "</pre>" ); out.println( "</HTML>" ); out.close(); } static public void main( String[] argv ) { print( new PrintWriter( System.out ) ); } }
Received on Monday, 8 June 1998 07:35:10 UTC