java.lang.ProcessBuilder.command(List<String> command)%uA0方法设置此进程生成器的操作系统程序和参数。此方法不会使命令列表的副本。后续更新的名单将反映在进程生成器的状态。它不检查command是否为一个有效的操作系统命令。
声明
以下是java.lang.ProcessBuilder.command()方法的声明
public ProcessBuilder command(List<String> command)
参数
-
command%uA0-- 包含程序和它的参数列表
返回值
此方法返回此进程生成器
异常
-
NullPointerException%uA0-- 如果参数为null
例子
下面的例子显示lang.ProcessBuilder.command()方法的使用。
package com.yiibai import java.io.IOException import java.util.ArrayList import java.util.List public class ProcessBuilderDemo { public static void main(String[] args) { // create a new list of arguments for our process List<String> list = new ArrayList<String>() list.add("notepad.exe") // create a new list that contains a file to open with notepad List<String> list2 = new ArrayList<String>() list.add("text.txt") // create the process builder ProcessBuilder pb = new ProcessBuilder(list) // set the command list pb.command(list) // print the new command list System.out.println("" + pb.command()) } }
让我们来编译和运行上面的程序,这将产生以下结果:
[notepad.exe, text.txt]