Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Nick Novello

  1. #1
    Junior Member nnovello's Avatar
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Nick Novello

    /*****************************************************************************
    *     
    *      Authored by Nicolas Novello in Fall 2010
    *      File JSwift.java is an ultralight code editor-not quite IDE. 
    *      Yes I reinvented the wheel... and I hope you like it. Watch out EMACS...lol
    *
    *
    *      Notes:
    *          Problem now is I realized that I need to be able to control the programs that iv'e compiled and ran.
    *          I have to have a way to kill zombie processes w/o having to pull it up in a terminal window or task                                       *          manager. Also, stdOutput is not printed until the running process is dead.  In fact, a the JSwift
    *          window locks out completely.  Iv'e dealt with server-client relationships before and they suck.
    *          Is there any other way to start in a new process while keeping old one awake?  
    ******************************************************************************/
     
    	public void runApp (){
    		try {
     
    				int fileParentPathLength = Global.file.getParentFile().getPath().length();  //used to find program name w/o full path
    				systemCommand = ("java " + Global.file.getPath().substring(fileParentPathLength+1,Global.file.getPath().length()-5)); //will not work for .jar!! must change classpath somehow too!
    				Global.infoBox.append(systemCommand + "\n");
     
    				//I need to create separate threads from current by calling these commands:
    				Runtime rt = Runtime.getRuntime();
    				Process pr = rt.exec(systemCommand); 
    				//gives this command to the os to let it take care of business
     
    				//then I need to somehow look for any runtime errors, exceptions...			
    				Scanner errorScanner = new Scanner(pr.getErrorStream());
    				while (errorScanner.hasNext()) Global.infoBox.append((errorScanner.nextLine()) + "\n");
     
    				//and also test for what the command is reading back from the stdoutput. 
    				//I guess Id have to put them both in a loop waiting for the process to be killed. terrible.
    				Scanner inputScanner = new Scanner(pr.getInputStream());
    				while (inputScanner.hasNext())Global.infoBox.append((inputScanner.nextLine())+"\n");
    Last edited by nnovello; November 21st, 2010 at 09:06 PM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Nick Novello

    In the future, please use the edit button.

    What is the problem you're experiencing (if any)? If it's an exception, please post the exception message in full.

  3. #3
    Junior Member nnovello's Avatar
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Nick Novello

    Sorry not to to be clear. No exceptions, no compile errors. It runs. It just doesn't work the way I want it too. I guess im looking for implementation help really. If I open up a Test program inside of the Client, compile it and run it. It all works. However, once a new program is running, the JSwift client is put to sleep. StdOutput will not be displayed until after the program that is being run is closed.
    Last edited by nnovello; November 21st, 2010 at 09:09 PM.
    /***************************
    *
    * Nick Novello
    * University At Buffalo
    *
    ***************************/

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Nick Novello

    .... Both standard out println commands should be executed before the jframe is executed.

  5. #5
    Junior Member nnovello's Avatar
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Nick Novello

    Right.. That is if Test.java is run in a working code editor like emacs or vim or eclipse or notepad or whatever your norm. is. But inside the JSwift editor that I wrote, that is not what happens. This is because when using the compileApp() and runApp() methods, I start a new process to execute the commands javac and java on my Test.java file. This puts my JSwift editor to sleep! So if the code Test.java that your running gets stuck in a while(true) loop, it cannot be stopped! (unless you manually kill the process). Another side affect is the inability of the JSwift editor to display any standard output until the new process is ended. My question is what is the simplest way to get past this?
    /***************************
    *
    * Nick Novello
    * University At Buffalo
    *
    ***************************/

  6. #6
    Junior Member nnovello's Avatar
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Nick Novello

    So the standard output from Test.java is executed before the JFrame is closed, but is not appended to my Global.infoBox until after it is closed.
    /***************************
    *
    * Nick Novello
    * University At Buffalo
    *
    ***************************/

  7. #7
    Junior Member nnovello's Avatar
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Nick Novello

    So instead of doing this:
    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec(systemCommand);

    Do I need to implement Runnable and start these tasks as new threads in another class?
    /***************************
    *
    * Nick Novello
    * University At Buffalo
    *
    ***************************/

Tags for this Thread