views:

158

answers:

1

Hello,

I need to pass parameter to remote beanshell script which is run through

java -cp bsh-2.0b4.jar bsh.Remote http://10.0.0.1/beanshell script.bsh p1 p2 p3

call.

Is it somehow possible to read params 'p1', 'p2' and 'p3' from within the script.bsh?

p.s. Local params passing through bsh.args works fine, but it's unusable with remote scripting.

A: 

I suppose, you are using beanshell library. There is no way to do so, according to sources: the utility takes only 2 arguments: the URL and the local script filename. It even does not support several script filenames, as it claim to.

public class Remote
{
    public static void main( String args[] ) throws Exception
    {
          if ( args.length < 2 ) {
                   System.out.println("usage: Remote URL(http|bsh) file [ file ] ... ");
                   System.exit(1);
          }
          String url = args[0];
          String text = getFile(args[1]);
          int ret = eval( url, text );
          System.exit( ret );
    }

Also the server-side should be aware about the arguments passed.

The ways out for you:

  1. Create the script template, in which you will substitute the arguments for the script and save the substitute script to temp dir before passing to bsh.Remote
  2. Create a remote file, where the script can read arguments from. You need additional communication with remote site to upload this file before calling bsh.Remote.
dma_k