Results 1 to 12 of 12
  1. #1
    Join Date
    May 2008
    Location
    India,Kolkatta
    Posts
    50
    Rep Power
    0

    Default [SOLVED] Close Exe

    Hi All,
    i want to close all exe that are open from my java application.
    For Example:
    if i open
    1. abc.doc
    2. gty.txt
    3. kju.pdf

    i want that when i close my application all these exe should be closed.
    Please help..
    thanks in advance..
    Thanks & Regards
    Subroto Bhattacharjee:)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    What do you mean by
    all exe that are open from my java application
    You list what I guess are the names of files.
    Does your program start a separate Process to "open" each of these files?

    Look at the API doc for Runtime and Process to see if there are any methods to do what you want.

  3. #3
    Join Date
    May 2008
    Location
    India,Kolkatta
    Posts
    50
    Rep Power
    0

    Default sorry for the Very Late reply

    here i not using any process, i use the following command to open the file

    Runtime run = Runtime.getRuntime();
    Process pp=run.exec("C:\\Windows\\notepad.exe"+" abc.dat");

    I use this so that i can open more than one file at a time but i dont how to close these file/s.
    For example if i open
    1) abc.dat
    2) xyz.dat
    3) sdf.dat

    and after working on this i want to close xyz.dat, then how can i achieve this..

    Please help..

    Thanks
    Thanks & Regards
    Subroto Bhattacharjee:)

  4. #4
    DevzAbhi's Avatar
    DevzAbhi is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default

    pp.destroy();

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    i want to close xyz.dat
    Close or kill notepad? The java program doesn't communicate with the notepad program to be able to tell it to close itself.Java does not have the file open, so I don't see how java can close the file. Either the user must click on the close button or you could use the Robot class to click on the close button. That'd be VERY tricky but might be doable.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default

    This works for me, but it doesn't prompt to save any changes typed during the 5 seconds that Notepad is open.
    Java Code:
    import java.io.IOException;
    
    public class CloseExe {
       public static void main(String[] args) {
          try {
             ProcessBuilder builder = new ProcessBuilder("Notepad.exe", "e:\\test.txt");
             Process process = builder.start();
             Thread.sleep(5000);
             process.destroy();
          } catch (InterruptedException ex) {
             ex.printStackTrace();
          } catch (IOException ex) {
             ex.printStackTrace();
          }
       }
    }
    db

  7. #7
    Join Date
    May 2008
    Location
    India,Kolkatta
    Posts
    50
    Rep Power
    0

    Default Thanks

    Thanks for you reply,

    Ya it works for closing the file.
    But in my program i dont want to run any process actually, thats why i only use Run command.
    because if i am running a process , then at a time i can open only one file but i want to open different files and do the job .
    thats why i want to close all the running application when i am exiting from the java application.

    Please help.

    in simple i want to close all the application which are running
    Thanks & Regards
    Subroto Bhattacharjee:)

  8. #8
    Join Date
    May 2008
    Location
    India,Kolkatta
    Posts
    50
    Rep Power
    0

    Default Here is the sample code

    import java.io.IOException;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;

    public class CloseExe {
    public CloseExe()
    {
    JFrame f1=new JFrame("Open");
    JPanel p1=new JPanel();
    f1.getContentPane().add(p1);
    JButton b1=new JButton("Open ABC.txt");
    JButton b2=new JButton("Open XYZ.txt");
    JButton b3=new JButton("Open SDF.txt");
    p1.add(b1);
    p1.add(b2);
    p1.add(b3);
    b1.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent er)
    {
    try
    {
    Runtime run = Runtime.getRuntime();
    Process pp=run.exec("C:\\Windows\\notepad.exe"+" d:\\abc.txt");

    }
    catch (Exception e)
    {
    e.printStackTrace();
    System.out.println(e.getMessage());
    }
    }
    });

    b2.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent er)
    {
    try
    {
    Runtime run = Runtime.getRuntime();
    Process pp=run.exec("C:\\Windows\\notepad.exe"+" d:\\xyz.txt");

    }
    catch (Exception e1)
    {
    e1.printStackTrace();
    System.out.println(e1.getMessage());
    }
    }
    });

    b3.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent er)
    {
    try
    {
    Runtime run = Runtime.getRuntime();
    Process pp=run.exec("C:\\Windows\\notepad.exe"+" d:\\sdf.txt");

    }
    catch (Exception e2)
    {
    e2.printStackTrace();
    System.out.println(e2.getMessage());
    }
    }
    });
    f1.setVisible(true);

    f1.setSize(300,300);
    f1.show();
    }
    public static void main(String[] args)
    {
    new CloseExe();
    }
    }


    Now, open all the notepads.
    what i want to do is.
    when i click on "X" button in the Java Application (Exiting the application) all the notepad should also be closed.

    Please help..
    Last edited by smartsubroto; 10-13-2008 at 07:37 AM.
    Thanks & Regards
    Subroto Bhattacharjee:)

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default

    WindowListener#windowClosing

    db

  10. #10
    Join Date
    May 2008
    Location
    India,Kolkatta
    Posts
    50
    Rep Power
    0

    Default

    ya, but how to close that files??????
    Thanks & Regards
    Subroto Bhattacharjee:)

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    Where is the file you want to close?
    If in the java program then use the close() method.
    If in another program, you have to tell that other program to do the close. The only why I know to have the other program close is to send a message from the java program to the user(a person) telling him/her to close the other program.
    You might be able to do it with the Robot class, but it would be very difficult.

  12. #12
    Join Date
    May 2008
    Location
    India,Kolkatta
    Posts
    50
    Rep Power
    0

    Smile Thanks..

    It is solved successfully..
    i simply set different name for a different process and destroy the processes in window closing event.

    Thanks to all of you...:)
    Thanks & Regards
    Subroto Bhattacharjee:)

Similar Threads

  1. JFrame Conditional Close
    By hemanthjava in forum AWT / Swing
    Replies: 10
    Last Post: 06-29-2008, 07:49 AM
  2. close a frame..
    By tajinvillage in forum New To Java
    Replies: 5
    Last Post: 04-27-2008, 10:22 PM
  3. Frame close operation
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-21-2007, 08:39 AM
  4. How to close a JFrame
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 05:33 PM
  5. Close a program in java
    By romina in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 07:22 PM

Posting Permissions

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