ANOMALIES TRYING TO COMPILE JAVA CODE FROM WITH IN A RUNNING JAVA APPLICATION

Discussion in 'Java' started by lbrtchx@hotmail.com, Jul 28, 2005.

  1. Guest

    // __
    [root@localhost XSD02]# javac javac02.java
    javac02.java:33: illegal escape character
    aCmmnd = new String[]{"echo","\$PATH"};

    // __ 1. java reachable from within my box' PATH

    [root@localhost XSD02]# echo $PATH
    /usr/kerberos/sbin:
    /usr/kerberos/bin:
    /usr/local/sbin:
    /usr/local/bin:
    /sbin:/bin:
    /usr/sbin:
    /usr/bin:
    /usr/X11R6/bin:
    /opt/jdk/jdk1.5.0_03/bin:
    /usr/local/jwsdp-1_6/jaxb/bin:
    /usr/local/ant/apache-ant-1.6.5/bin:
    /root/bin

    [root@localhost bin]# pwd
    /opt/jdk/jdk1.5.0_03/bin
    [root@localhost bin]# ls -l java*
    -rwxr-xr-x 1 root root 64492 Apr 13 06:55 java
    -rwxr-xr-x 1 root root 71632 Apr 13 06:55 javac
    -rwxr-xr-x 1 root root 71600 Apr 13 06:57 javadoc
    -rwxr-xr-x 1 root root 71600 Apr 13 06:57 javah
    -rwxr-xr-x 1 root root 71600 Apr 13 07:29 javap
    -r-xr-xr-x 1 root root 1789 Apr 13 07:27 java-rmi.cgi
    -rwxr-xr-x 1 root root 175978 Apr 13 07:54 javaws

    // __ 2. you can compile java source files from the command prompt, without any
    problems

    // __ 3. you can make system/OS's calls from a java source file

    import java.io.*;
    import java.util.*;

    class SysExec00{
    private Runtime RT;
    // __
    SysExec00(){ RT = Runtime.getRuntime(); }
    // __
    public String[] exec(String[] aCmmnd){
    ArrayList<String> ALS = new ArrayList<String>();
    String[] aSAr = null;
    // __
    try{
    Process Prx = RT.exec(aCmmnd);
    BufferedReader BR = new BufferedReader(new InputStreamReader(Prx.getInputStream()));
    String aLn = BR.readLine();
    while(aLn != null){ ALS.add(aLn); aLn = BR.readLine(); }
    }catch(IOException IOX){ IOX.printStackTrace(); }
    // __
    int iSz = ALS.size();
    if(iSz > 0){ aSAr = new String[iSz]; ALS.toArray(aSAr); }
    // __
    return(aSAr);
    }
    }

    // __
    public class javac02{
    public static void main(String[] aArgs){

    // __ OS calls are fine
    String[] aOut;
    String[] aCmmnd;
    SysExec00 SEx = new SysExec00();
    // __
    aCmmnd = new String[]{"ps","-aux"};
    aOut = SEx.exec(aCmmnd);
    if((aOut != null) && (aOut.length > 0)){
    for(int k = 0; (k < aOut.length); ++k){
    System.out.println("// __ aOut[" + k + "]: |" + aOut[k] + "|");
    }
    }// ((aOut != null) && (aOut.length > 0))

    // __
    aCmmnd = new String[]{"ls","-l"};
    aOut = SEx.exec(aCmmnd);
    if((aOut != null) && (aOut.length > 0)){
    for(int k = 0; (k < aOut.length); ++k){
    System.out.println("// __ aOut[" + k + "]: |" + aOut[k] + "|");
    }
    }// ((aOut != null) && (aOut.length > 0))

    /*
    // __ how to echo an environment variable?
    aCmmnd = new String[]{"echo","$PATH"};
    aOut = SEx.exec(aCmmnd);
    if((aOut != null) && (aOut.length > 0)){
    for(int k = 0; (k < aOut.length); ++k){
    System.out.println("// __ aOut[" + k + "]: |" + aOut[k] + "|");
    }
    }// ((aOut != null) && (aOut.length > 0))
    */

    // __ but trying to compile a class fails
    aCmmnd = new String[]{"javac", "./test00.java"};
    aOut = SEx.exec(aCmmnd);
    if((aOut != null) && (aOut.length > 0)){
    for(int k = 0; (k < aOut.length); ++k){
    System.out.println("// __ aOut[" + k + "]: |" + aOut[k] + "|");
    }
    }// ((aOut != null) && (aOut.length > 0))
    }
    }

    // __ 4. however trying to compile this simple piece of code:

    import java.util.*;

    public class test00{
    test00(){}
    // __
    public String getTime(){ return(new Date()); }
    // public String getTime(){ return(new Date().toString()); }
    // __
    public static void main(String[] aArgs){
    test00 t = new test00();
    System.err.println(t.getTime());
    }
    }

    gives you:
    [root@localhost XSD02]# javac test00.java
    test00.java:6: incompatible types
    found : java.util.Date
    required: java.lang.String
    public String getTime(){ return(new Date()); }
    ^
    1 error

    // __ 5. BUT NO ERRROS ARE SHOWN WHEN YOU DO THE COMPILING FROM WITHIN A RUNNING JAVA APP CALLING as tried through (see code snippet above):
    ....
    aCmmnd = new String[]{"javac", "./test00.java"};
    aOut = SEx.exec(aCmmnd);
    ....
    NO ERRORS ARE REPORTED

    // __ 6. fixing the code will allowed for the compilation of the class

    How do you get the errors from the compilation tried within a running JVM?
    <Albretch Muller>
    , Jul 28, 2005
    #1
    1. Advertising

  2. Re: ANOMALIES TRYING TO COMPILE JAVA CODE FROM WITH IN A RUNNINGJAVA APPLICATION

    wrote:
    > // __ 5. BUT NO ERRROS ARE SHOWN WHEN YOU DO THE COMPILING FROM WITHIN A RUNNING JAVA APP CALLING as tried through (see code snippet above):
    > ...
    > aCmmnd = new String[]{"javac", "./test00.java"};
    > aOut = SEx.exec(aCmmnd);
    > ...
    > NO ERRORS ARE REPORTED
    >
    > // __ 6. fixing the code will allowed for the compilation of the class
    >
    > How do you get the errors from the compilation tried within a running JVM?
    > <Albretch Muller>


    It looks like you do not read from the standard error stream of the
    child process, only the standard output.

    HTH,
    Ray

    --
    XML is the programmer's duct tape.
    Raymond DeCampo, Jul 28, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Paul Gloster

    Dealing with inheritance anomalies in Java

    Colin Paul Gloster, Sep 23, 2004, in forum: Java
    Replies:
    5
    Views:
    796
    P.Hill
    Sep 27, 2004
  2. Bailee
    Replies:
    9
    Views:
    621
  3. Nagaraj
    Replies:
    1
    Views:
    838
    Lionel B
    Mar 1, 2007
  4. Tony Proctor

    ASP Thread Scheduling Anomalies

    Tony Proctor, Mar 2, 2005, in forum: ASP General
    Replies:
    6
    Views:
    245
    Tony Proctor
    Mar 16, 2005
  5. Simon Wigzell

    Form anomalies on history.go(-1);

    Simon Wigzell, Nov 23, 2004, in forum: Javascript
    Replies:
    0
    Views:
    90
    Simon Wigzell
    Nov 23, 2004
Loading...

Share This Page