代码之家  ›  专栏  ›  技术社区  ›  Holograham

带有参数的VBA脚本的Java运行时执行

  •  2
  • Holograham  · 技术社区  · 16 年前

    我正在尝试使用runtime exec()运行带有参数的VBA脚本。我在通过ARG时遇到困难。我想我需要对exec使用string[]重载方法。

    目前这项工作:

    String command = "cmd /c \"\\concat2.vbs\""
    
    Process p = Runtime.getRuntime().exec(command);
    

    但是我想用参数来运行它,如果我这样做的话

    String command = "cmd /c \"\\concat2.vbs\" " + arg1 + " " + arg2
    

    其中arg1和arg2是字符串,我的程序不运行(状态=1)

    2 回复  |  直到 16 年前
        1
  •  0
  •   Cesar    16 年前
    < Buff行情>

    我想我需要用绳子 exec的重载方法

    < /块引用> 完全正确!将命令更改为字符串数组。数组必须包含命令及其参数:

    string[]command=“cmd”,“/c”,“concat2.vbs”,arg1,arg2_
    process p=runtime.getruntime().exec(命令);
    < /代码> 
    
    

    concat2.vbsshould be on window's execution path(same directory,or configured in the path environment variable)

    查看“http://java.xun.com /javas/6 /DOCS/API/Java/Lang/RunTime.html”执行%%Java.Lang.St[[]%Re=“NoFoLoLoeFror”>运行时类 ./P>文档> > 必须包含命令及其参数:

    String[] command = {"cmd","/c", "concat2.vbs", arg1, arg2};
    Process p = Runtime.getRuntime().exec(command);
    

    concat2.vbs应该在窗口的执行路径上(相同的目录,或在PATH环境变量中配置)

    退房运行时类的文档.

        2
  •  1
  •   decompiled    16 年前

    类似:

    String[] cmd = { "cmd", "/c", "concat2.vbs" "dog" "house" };
    Process p = Runtime.getRuntime().exec(cmd);
    

    应该产生“狗窝”