[Bluej-discuss] A weird bluej IDE. A bug?

Jason Zong zongzhaoguang at gmail.com
Sat Apr 15 11:07:28 BST 2006


hi everyone.

I am a fresh man here. Recently I program a small program, which I want to execute the specified string command in a separate process. Such as in a java program which could invoke java compiler to compile the specified java files.

I put the class TestCmd in D:\Test directory, also there are some other java source files.  I want the TestCmd to invoke the javac compiler to compile the specified java files which are stroed in c:\project\test2code. When I test my program, the weird thing happened. The process2 seems to find out a bug of bluej. 

Some time process2 failed in bluej. I commented the other three processes. It passes the compiling, if I run the program, it could fail sometime, and sometime it works well. When it failed, the system reports "bluej.shell doesn't exist ..." However the process2 always works well under the command line environment. 

Please everyone try to run this program and think about? What cause that happened. Here the program is posted below.

king regards
Yours Jason Zong




import java.io.*;
import java.lang.*;

//the TestCmd.java is stored in D:\Test directory.
public class TestCmd {

    public static void main(String args[]){
        File dir=new File("C:\\Projects\\test2Code");
        String[] cmds={"cmd.exe /k start dir","cmd.exe /k start javac *.java"};
        for(int i=0;i<cmds.length;i++){
            System.out.println(cmds[i]);
        }
        try{
            //list the files in the current directory, where we store TestCmd.class D:\test, passed in both bluej and command line
            Process  process1= Runtime.getRuntime().exec("cmd.exe /k start dir");
            
            //compile all the java files under the current directory, same as above. sometime failed in bluej but passed in command line
            Process  process2= Runtime.getRuntime().exec("cmd.exe /k start javac *.java");
            
            //compile all the java files under the specified directory c:\..., passed in both bluej and command line;
            Process  process3= Runtime.getRuntime().exec("cmd.exe /k start javac *.java",null,dir);
            
            //try to executes the specified commands and arguments in a separate process with specified working directory. failed in both.
            /*the exception information is weird, the systme output is "cmd.exe /k start dir" and "cmd.exe /k start javac *.java"
            * "java.io.IOException: CreateProcess: "cmd.exe \k start dir" "cmd.exe /k start javac *.java" error=2 ....."
            * 
            * That is so strange.
            */
            Process  process4= Runtime.getRuntime().exec(cmds,null,dir);
        }catch (IOException  e)
        {
            e.printStackTrace();
        }
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.bluej.org/pipermail/bluej-discuss/attachments/20060415/91e3a188/attachment-0001.html


More information about the bluej-discuss mailing list