envp - array of strings, each element of which has environment variable settings in format name=value.
就是环境变量,比如
{"os=winnt", "user=someone"}

解决方案 »

  1.   

    如果不用设置环境变量呢,好像envp不能为空
      

  2.   

    exec(String command)
    就可以了,有适用各种参数的方法嘛
      

  3.   

    envp 可以为空
    String[] commands,里是命令和参数
      

  4.   

    example:
    import java.io.BufferedInputStream;
    import java.io.IOException;
    import java.io.InputStream;public class Command2
    {
    public static void main(String[] args)
    {
    String cmd = "ping localhost";

    try
    {
    Process ps = Runtime.getRuntime().exec(cmd);
    System.out.print(loadStream(ps.getInputStream()));
    System.err.print(loadStream(ps.getErrorStream()));
    }
    catch(IOException ioe)
    {
    ioe.printStackTrace();
    }
    }

    // read an input-stream into a String
    private static String loadStream(InputStream is) throws IOException
    {
    int ptr = 0;

    BufferedInputStream bis = new BufferedInputStream(is);
    StringBuffer buffer = new StringBuffer();

    while( (ptr = bis.read()) != -1 )
    {
    buffer.append((char)ptr);
    }

    return buffer.toString();
    }
    }