Run the text only interpreter on the command line or specify a file.
( String [] args )
| 352 | Run the text only interpreter on the command line or specify a file. |
| 353 | */ |
| 354 | public static void main( String [] args ) |
| 355 | { |
| 356 | if ( args.length > 0 ) { |
| 357 | String filename = args[0]; |
| 358 | |
| 359 | String [] bshArgs; |
| 360 | if ( args.length > 1 ) { |
| 361 | bshArgs = new String [ args.length -1 ]; |
| 362 | System.arraycopy( args, 1, bshArgs, 0, args.length-1 ); |
| 363 | } else |
| 364 | bshArgs = new String [0]; |
| 365 | |
| 366 | Interpreter interpreter = new Interpreter(); |
| 367 | //System.out.println("run i = "+interpreter); |
| 368 | interpreter.setu( "bsh.args", bshArgs ); |
| 369 | try { |
| 370 | Object result = |
| 371 | interpreter.source( filename, interpreter.globalNameSpace ); |
| 372 | if ( result instanceof Class ) |
| 373 | try { |
| 374 | invokeMain( (Class)result, bshArgs ); |
| 375 | } catch ( Exception e ) |
| 376 | { |
| 377 | Object o = e; |
| 378 | if ( e instanceof InvocationTargetException ) |
| 379 | o = ((InvocationTargetException)e) |
| 380 | .getTargetException(); |
| 381 | System.err.println( |
| 382 | "Class: "+result+" main method threw exception:"+o); |
| 383 | } |
| 384 | } catch ( FileNotFoundException e ) { |
| 385 | System.err.println("File not found: "+e); |
| 386 | } catch ( TargetError e ) { |
| 387 | System.err.println("Script threw exception: "+e); |
| 388 | if ( e.inNativeCode() ) |
| 389 | e.printStackTrace( DEBUG, System.err ); |
| 390 | } catch ( EvalError e ) { |
| 391 | System.err.println("Evaluation Error: "+e); |
| 392 | } catch ( IOException e ) { |
| 393 | System.err.println("I/O Error: "+e); |
| 394 | } |
| 395 | } else |
| 396 | { |
| 397 | // Workaround for JDK bug 4071281, where system.in.available() |
| 398 | // returns too large a value. This bug has been fixed in JDK 1.2. |
| 399 | InputStream src; |
| 400 | if ( System.getProperty("os.name").startsWith("Windows") |
| 401 | && System.getProperty("java.version").startsWith("1.1.")) |
| 402 | { |
| 403 | src = new FilterInputStream(System.in) { |
| 404 | public int available() throws IOException { |
| 405 | return 0; |
| 406 | } |
| 407 | }; |
| 408 | } |
| 409 | else |
| 410 | src = System.in; |
| 411 |
nothing calls this directly
no test coverage detected