import java.io.*;
import java.util.*;
public class RuntimeDemo {
     public static void main(String args[]) throws IOException
     {
      //Runtime.getRuntime().exec("msconfig");
      Runtime.getRuntime().exec("mspaint");
     }
}
为什么mspaint能在eclipse下运行出来,而msconfig却运行不出来?
网友告诉我说只有能在cmd中运行的命令才能在exec(command)中运行出来,那怎样才能使msconfig运行出来呢?

解决方案 »

  1.   

    可以看看在path路径中有%SystemRoot%\system32;里面有notepad.exe,mspaint.exe所以执行时没问题
    Runtime.getRuntime().exec("C:\\WINDOWS\\pchealth\\helpctr\\binaries\\msconfig.exe"); 这样就可以了
    或者你设下path
      

  2.   

    环境变量path=.;
    或如楼上所说写全路径,写当前的可以将msconfig文件拷贝至当前文件夹即可。