try {
Process pro = null;
Runtime rt = Runtime.getRuntime();
for(int i = 0; i < strfl.length; i++){
            pro = rt.exec("cmd /c start copy d:\\" + strfl[i] + " d:\\new\\"+strfl[i]");
}
代码如上,如果strfl.length等于100的话,那么将打开100个cmd窗口!吓人哪!要是10000的话那就机器都爆了!
请问这个问题要如何解决?

解决方案 »

  1.   

    你每exec一下就会新开一个窗口的
      

  2.   

    在循环外执行啊
     ----------------------------循环外执行?是什么意思?
    我现在就是要循环执行很多条语句啊。只不过如果能只开一个cmd窗口,或者每次执行后把当前窗口关了的话,这样就可以了。
      

  3.   

    你每exec一下就会新开一个窗口的
     =======================
    就是要解决这个问题。
      

  4.   

    ("cmd /c start copy d:\\" + strfl[i] + " d:\\new\\"+strfl[i]"你把"start"去掉应该就可以了
      

  5.   

    在cmd下输入start就会另外打开一个窗口的,你循环了100次当然就打开100个了
    开不太明白什么意思,把start去掉应该没问题
      

  6.   

    你的这个str是个字符串是吗?
    怎么通过字符串的长度来做为循环条件呢?
    不理解!
      

  7.   

    String[] strfl = { "dir", "dir /w" };
    Process pro = null;
    Runtime rt = Runtime.getRuntime();
    for (int i = 0; i < strfl.length; i++) {
    try {
    1---  //pro = rt.exec("cmd /c start "+ strfl[i]);
    2--- pro = rt.exec("cmd "+ strfl[i]);
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    第一个好用 但是开了两个 doc 窗口
    第二个不好用?
    怎么在一个窗口执行两个命令 ?
    后在关闭doc窗口?
      

  8.   

    同意 EdmundBull 的解法。
    COPY 文件问题,自己书写程序也非常简单。