[Bluej-discuss] Continue discuss the inside BlueJ IDE, Runtime.exec().

Jason Zong zongzhaoguang at gmail.com
Tue Apr 18 16:55:21 BST 2006


Hi, Michael

Sorry for my poor english. Thanks for interest my question and reply this email.

> You are a bit unspecific about the error message you get -- when you
> say "the system reports", what does that mean? Does it appear in the
> BlueJ terminal? Or as an exception? In a dialogue? Or in your Windows
> system somewhere?

Sorry, I didn't specify the error message accurate. The systme reports that appears in a command line window. It pops up and give 2 lines messages and close the window quickly. It doesn't appear neither in BlueJ terminal nor exception.

As you know the Runtime.exec() method will create a native process and return a instance of subclass of Process that can be used to control the process and obtain information about it.  I want my program to compile the java files in the current working directory. So I wrote the statement "Process  process2= Runtime.getRuntime().exec("cmd.exe /k start javac 
*.java");" You could comment the other three process statements and compile the snippet , then run it under BlueJ IDE.

The snippet will create a native process which will run cmd command in the windows XP operating system. Then it tries to compile all the java file under the current working directory.  The wierd thing is that if I start run the main() method of the snippet from BlueJ, the native process (create a cmd window) will give two lines error message, and close that windows very quickly.I run it a few times, some times it will run well, some times it will show the following messages in a command line window and close that window very quickly. Finally I use prt sc caugh the windows. I attached it in the email. The messages are that first line is "_shellXX.java2: the package bluej.runtime doesn't exist." and second line is" public class _shellXX extends bluej.runtime.shell { ".  XX means a number such as 12,17. However if I start run the main() method of the snippet from command line, it will always work well.

> Also, is the message text really accurate? It looks suspicious to me.
> I clearly looks BlueJ related ("bluej.shell"), but BlueJ does not
> create any file or process with this name.
>
> When reporting error messages, please be specific and accurate, and
> tell us the complete message.
>
> So far, I can only guess. One guess is this: when you execute a
> method in BlueJ, BlueJ creates a .java file, compiles it, executes
> the class file, and after successful execution, removes it again.

I wrote a snippet, and execute the main method in BlueJ. The  BlueJ create a native process during running the main method. Some times there is error happened. I don't know the inside mechanism of the BlueJ how it works. Snice your email, I guess the process as following:

1. We select run the void main(String[]) method form the popup menus caused by right click on the class TestCmd icon in the BlueJ IDE.

2. The BlueJ create it's java file for execution, during the execution the cmd.exe process will be created and executed.

3. The cmd.exe scanning the current directory for *.java. As you said below, there is a BlueJ's generated java file, is that file a temporary file? Does BlueJ delete the file automatically? If yes, when would the BlueJ remove or delete the file generated by itself?

4. The cmd.exe passes the names to the javac process.

5. the javac process runs, receives the file names, and reports that  the file (the one created and removed by BlueJ) cannot be found. Hence the error messages are report. So do you think that caused by the java Garbage 
Collection or the side effect of BlueJ or my snippet?

If my guess correct, that could be explain why process3 works well but process2 doesn't.


Here another question why process4 has problem? If I comment the other three processes statements, compile and run the snippet in BlueJ, the BlueJ will report an exception as following.

java.io.IOException: CreateProcess: "cmd.exe \k start dir" "cmd.exe /k start 
javac *.java" error=2
 at java.lang.ProcessImpl.create(Native Method)
 at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
 at java.lang.ProcessImpl.start(ProcessImpl.java:30)
 at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
 at java.lang.Runtime.exec(Runtime.java:591)
 at TestCmd.main(TestCmd.java:29)
 at __SHELL31.run(__SHELL31.java:6)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at bluej.runtime.ExecServer$3.run(ExecServer.java:858)

Is that a bug or side effect? In my program I wrote the statment " String[] cmds={"cmd.exe /k start dir","cmd.exe /k start dir","cmd.exe /k start javac *.java");" why the system report "java.io.IOException: CreateProcess:"cmd.exe \k start dir" "cmd.exe /k start javac *.java" error=2" , I mean why the string /k is changed to \k in the BlueJ generated file 
__SHELL31.run(__SHELL31.java: 6).

Many Thanks. I'm very glad to you want to discuss this meanless snippet with me. Thank for your attention again.

King regards
Yours Jason.

Here I post the  snippet again.

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/20060418/77bcf8dc/attachment.html


More information about the bluej-discuss mailing list