【问题标题】:Java Runtime Exec for VBA script with arguments带有参数的 VBA 脚本的 Java Runtime Exec
【发布时间】:2010-05-18 17:24:44
【问题描述】:

我正在尝试使用 Runtime exec() 来运行带有争论的 vba 脚本。我在传递参数时遇到问题。我想我需要为 exec 使用 String[] 重载方法。

目前可行:

String command = "cmd /c \"\\concat2.vbs\""

Process p = Runtime.getRuntime().exec(command);

但我想用参数运行它,如果我这样做

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

其中 arg1 和 arg2 是我的程序未运行的字符串 (status = 1)

【问题讨论】:

    标签: java runtime.exec


    【解决方案1】:

    类似:

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

    应该产生“狗屋”

    【讨论】:

      【解决方案2】:

      我想我需要使用 String[] exec的重载方法

      没错!将您的命令更改为字符串数组。数组必须包含命令及其参数:

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

      concat2.vbs应该在Window的执行路径(同一个目录,或者在PATH环境变量中配置)

      查看documentation for the Runtime class

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-28
        • 2019-03-24
        • 2014-01-16
        • 2021-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多