Runtime rt = Runtime.getRuntime();
try { Process psPing = rt.exec("cmd.txt",null,new File("c:/"));
   
BufferedReader isPing = new BufferedReader(new InputStreamReader(psPing.getInputStream()));   
 String str = null;
             while((str = isPing.readLine())!= null){
                     System.out.println(str);
             }
             } catch(IOException   ex){   
              ex.printStackTrace();
              return;
         } 
这样读取c盘的文件为什么总是报createProcess错误
java.io.IOException: CreateProcess: cmd.txt error=2最好能提供个例子,谢谢大家了

解决方案 »

  1.   

    Runtime.getRuntime().exec这个方法怎么用?能不能执行*.pl文件
      

  2.   

    简单的,用写字板打开 c:\aa.txt 文本文件.
    注意系统的环境变量的path中设置了   %SystemRoot% 否则 系统找不到Notepad.exe 或者你直接把绝对路径写上
    import java.io.*;
    public class ExtRunTime 
    {
      public ExtRunTime() 
      {
      }
      public void execute()
      {
        Runtime   rt   =   Runtime.getRuntime(); 
        try  
        { 
          Process   psPing   =   rt.exec("notepad aa.txt ",null,new File("C:\\")); //rt.exec("c:\\notepad aa.txt ",null,new File("C:\\")); 
           
    //      BufferedReader   isPing   =   new   BufferedReader(new   InputStreamReader(psPing.getInputStream()));       
    //      String   str   =   null; 
    //      while((str   =   isPing.readLine())!=   null)
    //      { 
    //            System.out.println(str); 
    //      } 
        }  
        catch(IOException       ex)
        {
            ex.printStackTrace();
            return; 
        }   
      }
      public static void main(String arg[])
      {
        ExtRunTime run = new ExtRunTime();
        run.execute();
      }
    }
      

  3.   

    樓主,給你一個例子參考一下:import java.io.*;
    public class Test 
    {
    public static void main(String[] args) 
    {
    Runtime runtime = Runtime.getRuntime();
            Process p =null;

            try
    {
    p=runtime.exec("cmd /c start C:\\你的EXE路徑\\XX.EXE");

                    //下面是執行批處理的
                    //p=runtime.exec("cmd /c start R:\\WinAP\\MER\\Go-MER.BAT");
    //p.waitFor(); 
    }
    catch(Exception e )

    System.out.println(e.toString());
    } }
    }
      

  4.   

    用我这个吧,试过了,能运行
    Process   psPing   =   rt.exec("cmd /E:ON /c start c:\\cmd.txt"); 
      

  5.   

    这个程序执行*.pl文件吗?使用perl 命令
      

  6.   

    像javac一样,安装工具后才可以用的。这样能使用perl命令吗?能,该怎么使用
      

  7.   

    Process       psPing       =       rt.exec("cmd   /E:ON   /c   start   c:\\cmd.pl");
    试试,你要是装了相应软件的话