.exe文件可以如下调用Process aPro = Runtime.getRuntime().exec("d:\\alpha.exe");
//继续其它处理
aPro.destroy();
//结束

解决方案 »

  1.   

    不知道java  能不能不能调用API 函数!
    象 ShellExecute  这个函数我没有试过你可以试一试◎!~?
      

  2.   

    完了BAT文件还是不行呀
    Process aPro = Runtime.getRuntime().bat("d:\\alpha.bat");它提示BAT不可以
      

  3.   

    请问怎样调用内部命令,如dir,copy等。我正在做实验报告,用java实现微型command shell
      

  4.   

    dir,copy好像是要用JAVA写,不知道能不能调用似乎不能
      

  5.   

    String[] command = {"/*命令*/"};
                
                Process p = Runtime.getRuntime().exec(command);
                p.waitFor(); %>
    你这样试试看!:)我也不知道可不可以! 我只是提参考的:)
      

  6.   

    这是一个简单的调用ping.exe的程序,你可以参考一下import java.net.*;
    import java.io.*;public class javaPing{
    public static void main(String[] args){
    String pingurl=null;
    if(args.length>0) { 
    pingurl=args[0];
    }
    else {
    pingurl="www.sina.com.cn";
    }
    pingurl="C:\\WINNT\\system32\\ping.exe "+pingurl;

    try 

    Process process = Runtime.getRuntime().exec ("pingurl"); 
    InputStreamReader ir=new InputStreamReader(process.getInputStream()); 
    LineNumberReader input = new LineNumberReader (ir); 
    String line; 
    while ((line = input.readLine ()) != null) 
    System.out.println(line); 

    catch (java.io.IOException e){ 
    System.err.println ("IOException " + e.getMessage()); 

    }
    }
      

  7.   

    你说的方式只能调用外部命令,不能调用内部命令如dir,del,copy等。
    我想要实现的如C里面的system()函数,它内外部命令都可调用,
    而我只要调用内部命令。
      

  8.   

    实际上,dir, del,copy都是类似ping的一个个小工具,所以它们都是一样的
    如果你设了环境变量,就可以直接在下面一句写上
    Process process = Runtime.getRuntime().exec ("dir"); 
    Process process = Runtime.getRuntime().exec ("del *.*"); 
    Process process = Runtime.getRuntime().exec ("pine www.163.com"); 
      

  9.   

    import java.io.*;
    class test
    {
    public static void main(String []args)
    {
    try{
    Process process = Runtime.getRuntime().exec("dir");
    }
    catch(IOException e)
    {
       System.out.println(e.getMessage());
    }
    }



    }
    以上代码在我机器上显示:
    CreateProcess: dir error=2
    如果是外部命令就正常,我设置过CLASSPATH 和path
      

  10.   

    import java.io.*;
    class test
    {
    public static void main(String []args)
    {
    try{
    Process process = Runtime.getRuntime().exec("dir");
    }
    catch(IOException e)
    {
       System.out.println(e.getMessage());
    }
    }}
    以上程序在你们的机器上可以调用dir吗?