Run External application without Exiting main application

Hi,
I am trying to implement a function that executes the external program from within my java application. I am using windows xp. I had googled for this and found some code but so far I am able to run the application in a condition if my main application exits. Instead I want to run the application without exiting my main application. How can I do that:
Code I am using is:
========================
try{
Runtime.getRuntime().exec("external program");
System.exit(0);
catch (Exception err){
err.printStackTrace();
System.exit(-1);
=========================
my problem is I cannot run the external program without the line "System.exit(0)". If I remove that line, the external program only starts after I exit my main java application. Is there a way to run the external application without leaving the main application?
By the way I am using the latest version of JDK 6 update 2 and Netbeans 5.5.1
Thanks

I tried and I tried and I couldn't make the same problem occur unless I specfically had a long task execute BEFORE calling the runtime command. See the code below:
I tried a bunch of things, including having a GUI run before the Runtime call, after the runtime call. Neither affected the movie from being played.
I tried with different versions of the runtime command, none of it made a problem.
I tried running the application with a long task that would keep the main thread busy for a while AFTER I launched mplayer - no problem.
The only thing that made the app work the way you describe was when I built the long task that keeps the main thread active for a while BEFORE I launched mplayer (which is the state of the code as I pasted it below).
So my guess is that you have a single threaded application and you add the call to mplayer at the very end of your program's execution - thus it doesn't get called until the last thing. My suggestions:
1) Move the call to the Start of your code, not the end
2) Move your other work to a new thread so that it can be kicked off without holding the main thread in check.
package movies;
import inheritance.BaseWindow;
import java.util.*;
import java.io.*;
class StreamGobbler extends Thread
    InputStream is;
    String type;
    OutputStream os;
    StreamGobbler(InputStream is, String type)
        this(is, type, null);
    StreamGobbler(InputStream is, String type, OutputStream redirect)
        this.is = is;
        this.type = type;
        this.os = redirect;
    public void run()
        try
            PrintWriter pw = null;
            if (os != null)
                pw = new PrintWriter(os);
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line=null;
            while ( (line = br.readLine()) != null)
                if (pw != null)
                    pw.println(line);
                System.out.println(type + ">" + line);   
            if (pw != null)
                pw.flush();
        } catch (IOException ioe)
            ioe.printStackTrace(); 
public class MyMainClass
    public static void main(String args[]) throws InterruptedException
         //This is just a GUI as a test
        BaseWindow bw = new BaseWindow();
        bw.show();
        //Keep App Running for a while
        int count = 0;
        while (count < 200) {
             Thread.sleep(20);
             count++;
             System.err.println(count);
        if (args.length != 1)
            System.out.println("USAGE java movies.MyMainClass \"<movie to play>\"");
            System.exit(1);
        try
            Runtime rt = Runtime.getRuntime();
            //String[] cmds = new String[] { "cmd", "/c", "C:\\Mplayer\\mplayer.exe", args[0]};
            //String[] cmds = new String[] { "C:\\Mplayer\\mplayer.exe", args[0]};
            //Process proc = rt.exec(cmds);
            Process proc = rt.exec("C:\\Mplayer\\mplayer.exe "+args[0]);
            // any error message?
            StreamGobbler errorGobbler = new
                StreamGobbler(proc.getErrorStream(), "ERROR");           
            // any output?
            StreamGobbler outputGobbler = new
                StreamGobbler(proc.getInputStream(), "OUTPUT");
            // kick them off
            errorGobbler.start();
            outputGobbler.start();
            //Keep App Running for a while
//            int count = 0;
//          while (count < 2000000) {
//                 Thread.sleep(200);
//                 count++;
//                 System.err.println(count);
            // any error???
            int exitVal = proc.waitFor();
            System.out.println("ExitValue: " + exitVal);
        } catch (Throwable t)
            t.printStackTrace();
}I will restate myself:
"I was not able to repeat the problem, except as described, as long as I took the hints mentioned in the article I posted into account and actually put them into action."
Of course, as soon as I ignored those hints, I was able to reproduce the error described above quite easily in all the different tests I made... But I guess the OP implemented those fixes, right? He did say he read the article...
Message was edited by:
stevejluke

Similar Messages

  • How to close sub-application without close main-application?

    My main application has a menu which is used to open sub-application window. When I want to close the sub-application, I do not want to use System.exit(0), because it will close the main-application too.
    And if I use setVisible(false), the sub-application remains in memory.
    How can I close a sub-application clearly and keep the main-application open?

    Stephen:
    Some other object may be holding reference to this object.
    Here is how you debug such as problem.
    1. Run your app in the IDE's debugger.
    2. After you think all refs to the object should have gone away, pause the debug session.
    3. Using the View/Debug Windows/Heap menu, bring up the heap window.
    4. Right mouse click on the heap window. Enter the class name (package qualified) of the object which isn't being collected.
    5. Then, find the object that instance. Select it.
    6. Do right mouse click on that and select 'Show Reference Paths.'
    It will show paths to this object. It will show you who's holding ref to this object, preventing it from being garbage collected.
    Thanks.
    Sung

  • On clicking a button run external class which refrances main application

    I have a reader ReadXML and a Jframe Cpass, on clicking a button on Cpass, an new filechooser opens, this then fills the input jtextfiled12 . When clicking "load" button on cpass I need to send jtextfiled12.getText() to ReadXML (this runs, and updates mank text fields on cPass)... but I cant reference from a static context Cpass>>ReadXML>>Cpass.... so having a problem
    relevant cPass in cPass.java:
    public class Cpass extends javax.swing.JFrame {
    public static void main(String args[]) {
    Cpass C = new Cpass();
         C.show();
    public String getIn() {        return this.jTextField12.getText();         }
    relevant ReadXML in ReadXML.java:
    public class ReadXML {
    private void ReadInXML() throws IOException {
         String XmlInText = Cpass.getIn();
              BufferedReader allData8 = new BufferedReader(new InputStreamReader
    (new FileInputStream(new File( XmlInText)),"UTF8")); }
    Edited by: Mr_Tuition on Dec 5, 2007 3:44 AM

    but since cpass is already running from cpass, i cant reinitialise it, I need to used the insatance that is already shown, since it contains the infomation needed to pass to readXML
    public static void main(String args[]) {
       Cpass C = new Cpass();
       C.show();
       }When selectinfg a button on C (which selects the file location), that then opens readXML, I cant open a new version of Cpass (since this wont contain the infomation, eg the file the user has just chosen)
    I need to run Cpass
    Click a button that selects a file
    then file location is set in a text feild on Cpass
    on selecting "load" on Cpass, this runs readXML.java
    *readXML some how gets the file location from Cpass (which is still C.show();)
    the XML is read, and sent back to Cpass via:
              public String[] getStrAllData() {
                      return this.arrayXML;
             }One way arround thios is to copy the readXML function into Cpass but thats just messy
    Another would be to write out a "cookie" type file that saves the location, then readXML can use this .. less messy, but not what I wanted.
    Edited by: Mr_Tuition on Dec 5, 2007 4:42 AM

  • Scrolling Main Menu Without Exiting Current Application

    The problem I'm facing is that i cannot scroll the main menu without exiting any current application. For instance if I'm logged on to Skype i cannot do anything else till i don't exit out of it. In that case i've get signed out of it. So is the case with many other applications.. If any solution please let me know. Thanks

    This is how the iPhone works. Only one app can be open at a time. You cannot leave one to go to another without closing it.

  • Always that i load an applications loads all main applications

    Always that i upload a new cod file loads main applications
    net rizmic etc
    why not only the cod file then it freezes on startup and i have to reset it

    See:
    *http://kb.mozillazine.org/Preferences_not_saved
    *https://support.mozilla.com/kb/Preferences+are+not+saved

  • Running a java application without a main method

    class MainMethodNot
        static
            System.out.println("This java program have run without the run method");
            System.exit(0);
    }The reason this works is that static initialization blocks get executed as soon as the class is loaded, even before the main method is called. During run time JVM will search for the main method after exiting from this block. If it does not find the main method, it throws an exception. To avoid the exception System.exit(0); statement is used which terminates the program at the end of the static block itself.
    got it from http://www.java-tips.org/

    This has been published many times on this forum. What is your question?

  • Run function in component from Main Application

    Hello all.
    I have my main.mxml application, that has a component inside of it.  The component is called <ns1:record/> with an id of "rec".
    This component has a function inside of it named doConnect(event:MouseEvent).
    Now i want to be able to add an event listener to a button on the Main.mxml that will run a function inside the component when clicked.
    I have managed to add an event listener to the Main.mxml that triggers a function held within the Main.mxml when a button clicked inside the component is clicked.
    I did this by using this code.
                <ns1:record id="rec" x="9" y="6" camera="{camera}" microphone="{microphone}" creationComplete="makeEvent()">
                </ns1:record>             //Event listener
                public function makeEvent():void {
                    rec.backbtn.addEventListener(MouseEvent.CLICK,swapstate);
                protected function swapstate(event:MouseEvent):void {
                    viewstack1.selectedChild=config;
    No matter what i try thou i cant get this to work the other way around.
    What i need help with is - clicking a button within the Main.mxml to run a function inside the component Record.
    If anyone can help that would be great !
    Thanks in advance.

    Hi djh88ukwb,
    From your post if I understand you correctly you want to listen for a event in record component when a button in main mxml is clicked...based on this
    assumption I am suggesting you a solution...
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onCreationComplete()">
    <mx:Script>
      <![CDATA[
       private function onButtonClicked(event:MouseEvent):void
       rec.swapstate(event);
      ]]>
    </mx:Script>
    <ns1:record id="rec" x="9" y="6" camera="{camera}" microphone="{microphone}" creationComplete="makeEvent()"></ns1:record>
    <mx:Button id="myBtn" label="Call Function in Record Comp" click="onButtonClicked()" />
    </mx:Application>
    <!-- In your record component Add a public function  swapstate as shown below-->
    public function swapstate(event:MouseEvent):void {
                    viewstack1.selectedChild=config;
    Please try this and let me know....
    Thanks,
    Bhasker

  • Closing a form without exiting the application

    FORM_A calls FORM_B. FORM_A needs user's input (parameters). FORM_A passes those parameters to FORM_B. After the user is finish with FORM_B (which has the details about the parameters passed) I would like for them to close that form and go back to FORM_A to start the process all over again. On FORM_B I have an exit button with the code of: close_form('FORM_B'); this doesn't work it closes the whole application. How can I make this work? I am using Forms 6i/Oracle 7.3.4 database.
    Thanks in advance.
    ~Vannette

    Christian,
    Form_A has this code when opening FORM_B:
    call_form('FORM_B',NO_HIDE, DO_REPLACE, NO_QUERY_ONLY,param_list_id);
    FORM_B has this code when closing form (FORM_B):
    DECLARE
         fm_id varchar2(25);
    BEGIN
         fm_id := :System.Current_Form;
         close_form(fm_id);
    end;     
    At first I had the following code on FORM_B
    exit_form(NO_COMMIT);

  • Macbook pro 2010 with 2 external monitors without its main display

    Hi guys, I have been searching for a way to have 2 monitors without macbook's screen itself.
    I'm aware of various adapters through usb and etc.
    But Im thinking, if mac book is only capable of outputing 2 displays, why not outputing main display to one external monitor, instead of the screen on the computer, and the other external montior as a extra one?
    Is it possible ?  so basically 2 external monitor with macbooks screen switched off.
    I don't think apple tv can mirror one and add extra one   can it?
    I just want 2 big monitors instead of 1 big monitor with 1 tiny screen of the laptop.

    Maybe someone with a 2010 model will jump in and correct me, but as you only have a single Mini DsplayPort adapter, I don't think that it's possible to have two external models on a 2010 model. You can only do it on 2011+ via Thunderbolt using Thunderbolt Displays.
    You might want to ask your question in the Apple Cinema Display forum, though. I'm just not aware that it can be done.
    Clinton

  • Any way to install individual Windows Essential applications without updating existing applications?

    Hi, I'd like to take advantage of some of the recent versions of software included in Windows Essentials, but I don't want to update my MSN Messenger 2009 to a newer version as I dislike the UI in newer versions. Is this possible and how do I go about doing
    this if it is?
    I understand MSN Messenger will be succeeded by Skype eventually, but until then I like MSN Messenger 2009 for general chatting as it's UI has more defined boundaries for each element of the UI instead of it all just being seamless and bland white.
    Core i7 920 @ 2.66GHZ | ASUS P6T Mother Board | 6 gig DDR3 1600 RAM | 2x 500g SATA2 HDD | Integrated sound | Gainward Geforce GTX 560Ti "Phantom 2" 2048MB PCI-E (latest drivers) | Windows 7 Home Premium x64 | Thermaltake 750watt Toughpower Power
    Supply | Thermaltake Armor+ MX case.

    Hi,
    It would be about Appsearch action, this online installation would search for a specific file or directory during an installation. File or directory searches are used to determine whether a user has already installed a version of an application. It
    seems this search is for all components, not a single part.
    If you have any feedback on our support, please click
    here
    Alex Zhao
    TechNet Community Support

  • How to contain a sub-component in the module instead of containing it in the main application

    Hi,
    I've 3 files
    Appln.mxml (application file)  ----  contains main application
    component.mxml (component file)  ----  contains component
    module.mxml (module file)  -----  contains module
    Generally the 'component.mxml' file will get loaded into the 'Appln.mxml' file (i.e., 'Appln.mxml' file will contain the custom component files) and whereas module file will get loaded on-demand.
    So Now instead of containing the data of 'component.mxml' file in the 'Appln.mxml',  I want to contain 'component.mxml' file data in the 'module.mxml' file itself and load the 'component.mxml' when module is loaded on-demand but not when application is loaded. So can any one please suggest me how to do it?
    Thanks in advance..

    Theo--
    You can delete software components & versions from the IR in XI 2.0.  (We're on Service Pack 5, and I've done it to clean up our IR.)
    Here is the process:
    1. Delete all configuration and/or import objects from the SCV.  Don't forget the 2 fault data types that SAP automatically creates in every namespace.
    1a.  Activate all change lists?  I don't remember for certain if this is needed here; if it won't let you save the deleted namespaces in step 2, then do this first.
    2. Double-click on the Software Component Version so that it comes up in the right pane.  Click on the change/edit button.  Delete all the namespaces from the SCV.  Save.
    3. Activate all change lists.  (It won't let you delete the SCV if you have uncommitted changes.)
    4. Open the SCV again (if it's not still open).  On the menu at the top of the right pane, go to Software Component Version...Delete.  You may or may not have to activate changes again.
    If I remember right, the software component will disappear automatically with the deletion of the last version.
    Hope this helps!
    --Dan King
    Capgemini

  • Event propagation from child application to main application

    Hi,
          I am using SWFLoader to load third party component into our main application.we are trying to create annotation feature on top of child application.for that main application needs to receive events e.g. mouse events from child application.can anyone suggest whether this is possible ?
          I found pdf doc from help of SWFLoader component on flex developmenent center.It has an example in which child application uses SystemManager to register event listner for main application.so is it that we need to register listener from child application so main application receive events ?
       Thanks in advance.
    Thanks and regards,
    Rakesh Parmar

    If you examine the urls and the domains are the same then you don't have a cross-domain problem, but then your symptoms remain unexplained.
    Note that Flash just checks the text of the domain/sub-domain so http://localhost/ is different from http://10.0.0.127/ or whatever its IP equivalent is.
    Alex Harui
    Flex SDK Developer
    Adobe Systems Inc.
    Blog: http://blogs.adobe.com/aharui

  • How can i run external application without specifying the full path?

    for example, ms word executable file is winword.exe, but in java i am using the following command:
    Runtime.getRuntime().exec("\"C:\\Program Files\\Microsoft Office\\Office10\\winword.exe\");
    the thing is, i dont know where ms word is installed on every machine, so rather than making an assumption, do you know how i can run ms word without specifying the full path?
    thanks

    1) You could ask the user to tell you where it's at (and remember for next time)
    2) You could do a file search for it (and remember it for next time)

  • Running a GUI application without holding command prompt

    Hi there ,
    I have developed a GUI application using Swing. After compiling the same successfully , when I run the same , presently , I am running it like ,
    c:\> java xxx
    where c:\ is the general command prompt on a Windows machine where I can type in my commands like javac or java and xxx is the class file name . Now till I complete using my GUI application and exit from the same , the command prompt will also be there ( and probably displaying the output of my System.out.println ) . So , two sessions are running , one is just the command prompt and another is the actual GUI application.
    How can I avoide this ? e.g. when I type command "notepad" and press enter , notepad is started and the command prompt returns after starting notepad i.e. the notepad and the command prompt are not related now , I can close the command intrepreter and still notepad is running . What should I do to create such a Java GUI application ? Please advice .

    If I understand you correctly this is something that happens in linux also. And I believe that you can solve this by creating to shortcut to this program.
    And the shortcut or link to application will be the command line that you use to run the Java Application.
    i.e.
    java c:\javadir\subjavadir\application.class
    And I believe that this will allow it to run without the command prompt. Just showing the GUI and no additional command prompt window. Freeing the command prompt is something that I don't know how to do in either OS.
    I use the Link To Application method because I ultimately don't need to have multiple windows for one application. Even though it is nice to be able to kill the Application by destroying the command-prompt session (in case your app causes lock-ups during testing).
    Post your results . . . I'm not even sure that I'm being clear at all with my explanation to your question.

  • Running ABAP Web Dynpro Application without host entry of web server

    Hi All,
    I am trying to run a web dynpro application, its working fine when I have done host entry (host nam.domain.extension) of web server.
    But when I remove this entry from host file it not runs.
    Can you tell me the posibility of running this application without host entry? Based on this possibility I have to proceed my work. Please guide me.
    Thanks and Regards
    Sudhir Gupta

    Hi Sudhir ,
    See the below link , its necessary to provide FQDN.
    http://help.sap.com/saphelp_nw70/helpdata/en/67/be9442572e1231e10000000a1550b0/frameset.htm
    Regards
    Yash

Maybe you are looking for