Java的脚本BeanShell的使用对程序ARGS []? [英] Java Beanshell scripting with args[] to the the program?

查看:390
本文介绍了Java的脚本BeanShell的使用对程序ARGS []?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助 BeanShell的文档意味着您可以使用此格式运行脚本命令行:

 的Java bsh.Inter preTER script.bsh [参数]

这个唯一的问题是,我不能得到它的工作。我知道如何调用其他脚本与ARGS从BeanShell的脚本,但我不能让最初的剧本拿ARGS。帮助?

例如,像这样的一个剧本的BeanShell,不会解析ARGS:

 进口的java.util。*;
的for(int i = 0; I< args.length;我++){
  的System.out.println(精氨酸:+ ARGS [I]);
}

另外,该不工作或者:

 进口bsh.Inter preTER;
为(ⅰ:bsh.args)
的System.out.println(ⅰ);


解决方案

命令行参数是在 bsh.args 用,未 ARGS 。所以,如果你改变 ARGS 的所有实例在code。与 bsh.args ,你要善于走。参考:特殊变量和值


这为我工作:

 为(ARG:bsh.args)
    打印(ARG);

例如:

  $ BSH foo.bsh 1 2 3
1
2
3

The Beanshell documentation implies that you can run a script using this format on the command line:

java bsh.Interpreter script.bsh [args]

The only problem with this is that I cannot get it to work. I know how to call other scripts with args from a Beanshell script but I cannot get the initial script to take args. Help?

For example, a beanshell script like this one, wont parse the args:

import java.util.*;
for (int i=0; i < args.length; i++) {
  System.out.println("Arg: " + args[i]);
}

Also, this doesn't work either:

import bsh.Interpreter;
for( i : bsh.args )
System.out.println( i );

解决方案

The command-line arguments are available under bsh.args, not args. So if you change all instances of args in your code with bsh.args, you should be good to go. Reference: Special Variables and Values.


This worked for me:

for (arg : bsh.args)
    print(arg);

Example:

$ bsh foo.bsh 1 2 3
1
2
3

这篇关于Java的脚本BeanShell的使用对程序ARGS []?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆