home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Shareware / Comunicatii / advwebrank / awr.msi / disk1.cab / bsh_1.2b6.jar / bsh / commands / run.bsh < prev    next >
Encoding:
Text File  |  2002-05-24  |  1.7 KB  |  51 lines

  1. /**
  2.     Run a command in its own in its own private global namespace and interpeter
  3.     context.  (kind of like the unix "chroot" for the namespace)
  4.     The root bsh system object is extended (with the extend() command) and 
  5.     made visible here, so that system info is effectively inherited.
  6.     Because the root bsh object is extended it is effectively read / copy
  7.     on write...  e.g. you can change directories in the child context, do
  8.     imports, etc. and it will not affect the calling context.
  9.     <p>
  10.  
  11.     run() is like source() except that it runs the command in a new, 
  12.     subordinate and prune()'d namespace.  So it's like "running" a command 
  13.     instead of "sourcing" it.  Returns the object context in which the command
  14.     was run.
  15.     <p>
  16.  
  17.     Returns the context so that you can gather results.
  18.     <p>
  19.     Paramameter runArgument an argument passed to the child context under the
  20.         name runArgument.  e.g. you might pass in the calling This context
  21.         from which to draw variables, etc.
  22.     <p>
  23.  
  24.     @return Returns the context so that you can gather results.
  25.     @param runArgument an argument passed to the child context under the
  26.         name runArgument.  e.g. you might pass in the calling This context
  27.         from which to draw variables, etc.
  28. */
  29.  
  30. bsh.help.run= "usage: Thread run( filename )";
  31.  
  32. run( String filename, Object runArgument ) 
  33. {
  34.     // Our local namespace is going to be the new root (global)
  35.     // make local copies of the system stuff.
  36.     //
  37.     // Extend the root system object
  38.     // this is problematic...  probably need more here...
  39.     bsh=extend(global.bsh); 
  40.     bsh.help=extend(bsh.help);
  41.  
  42.     // cut us off... make us the root (global) namespace for this command
  43.     this.namespace.prune();
  44.     this.interpreter.source( filename, this.namespace );
  45.     return this;
  46. }
  47.  
  48. run( String filename ) {
  49.     run( filename, null );
  50. }
  51.