Results 1 to 6 of 6
  1. #1
    debylni is offline Member
    Join Date
    Mar 2010
    Location
    Bretejovce, Slovakia
    Posts
    4
    Rep Power
    0

    Exclamation Weird java problems

    Hi, I'm coding an application for writing java code and I'm trying to add a sort of console where the code output goes. I tried to use Process class and exec("...") method. I typed in "javac xxx.java && java xxx". It threw an exception (java haven't recognised '&&' symbol). So I tried to split it into two processes but when I call "javac xxx.java", whole program freezes (but bytecode is created). Can someone help me?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by debylni View Post
    Hi, I'm coding an application for writing java code and I'm trying to add a sort of console where the code output goes. I tried to use Process class and exec("...") method. I typed in "javac xxx.java && java xxx". It threw an exception (java haven't recognised '&&' symbol). So I tried to split it into two processes but when I call "javac xxx.java", whole program freezes (but bytecode is created). Can someone help me?
    Exec the other process in an independent thread so your original thread can start the exec( ... ) of the second process?

    kind regards,

    Jos

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Read and implement all teh recommendations on all pages of this:
    When Runtime.exec() won't - JavaWorld

    db

  4. #4
    debylni is offline Member
    Join Date
    Mar 2010
    Location
    Bretejovce, Slovakia
    Posts
    4
    Rep Power
    0

    Default

    Uh, well... There're still problems. Java throws: java.io.IOException: Cannot run program "javac E:\HelloWorld.java": CreateProcess error=2, System cannot find the specified file
    at java.lang.ProcessBuilder.start(ProcessBuilder.java :459)
    at java.lang.Runtime.exec(Runtime.java:593)
    at java.lang.Runtime.exec(Runtime.java:466)
    at TestingInProgress.Console.compileAndRun(Console.ja va:39)
    at TestingInProgress.Console.actionPerformed(Console. java:52)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6263)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
    at java.awt.Component.processEvent(Component.java:602 8)
    at java.awt.Container.processEvent(Container.java:204 1)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4630)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4574)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2475 )
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)
    Caused by: java.io.IOException: CreateProcess error=2, System cannot find the specified file
    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 :452)
    ... 29 more



    Here is my code:
    Java Code:
        
    public void compileAndRun() throws IOException {
            String[] cmds = {"javac E:\\HelloWorld.java", "java E:\\HelloWorld"};
            String s = null;
            Process run = Runtime.getRuntime().exec(cmds);
            BufferedReader stdIn = new BufferedReader(new InputStreamReader(run.getInputStream()));
            BufferedReader stdErr = new BufferedReader(new InputStreamReader(run.getErrorStream()));
            while((s = stdIn.readLine()) != null) {
                con.append(s + "\n");
            }
            while((s = stdErr.readLine()) != null) {
                con.append(s + "\n");
            }
        }

  5. #5
    debylni is offline Member
    Join Date
    Mar 2010
    Location
    Bretejovce, Slovakia
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Exec the other process in an independent thread so your original thread can start the exec( ... ) of the second process?

    kind regards,

    Jos
    Well, splitting into two threads doesn't work. It still freezes.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by debylni View Post
    Well, splitting into two threads doesn't work. It still freezes.
    Well, you're still doing something wrong then; read this article.

    kind regards,

    Jos

Similar Threads

  1. Weird output
    By gandalf5166 in forum New To Java
    Replies: 2
    Last Post: 02-28-2010, 10:17 PM
  2. weird problem
    By GPB in forum New To Java
    Replies: 2
    Last Post: 02-28-2010, 01:04 PM
  3. Seriously weird output
    By gandalf5166 in forum Java Applets
    Replies: 4
    Last Post: 02-27-2010, 05:16 AM
  4. Weird Error?
    By sciguy77 in forum New To Java
    Replies: 4
    Last Post: 01-20-2009, 03:32 AM
  5. Replies: 9
    Last Post: 09-30-2008, 08:30 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •