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 6 of 6

Thread: java program to execute an external application

  1. #1
    Junior Member
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java program to execute an external application

    Hi,

    I want to create a java program to find the applications running in my computer. And then I want to select a particular application called 'Harvest Client.exec'. Bring the application to front. And Then find a textbox in it and paste the things from clipboard.

    I am not sure how to do this. I started by using some Runtime methods. But I am not getting anywhere. Can anyone please tell me, what I should use?

    Thanks a lot for your help and time.

    Best Regards,
    Harleen


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: java program to execute an external application

    This isn't really a job for Java.

    You might be able to hack it using the Robot class, but going the way you're thinking about is going to require native code.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java program to execute an external application

    Thanks Kevin. My colleague has done this in C#.
    There must be a way to do this in Java.

    I have started like this:

    import java.io.*;
    import java.util.Map;
    public class hotkey {
    public static void main (String[] args) {

    try {

    String line;

    Process p = Runtime.getRuntime().exec (System.getenv("windir") +"\\system32\\"+"tasklist.exe");

    BufferedReader input =
    new BufferedReader(new InputStreamReader(p.getInputStream()));

    while ((line = input.readLine()) != null) {

    if(line.length()!=0)
    {

    if(line.substring(0,18).equals("Harvest Client.exe"))
    System.out.println("hehe");
    }
    }

    input.close();


    //Process p2 = Runtime.getRuntime().exec("Harvest Client.exe");

    }
    catch (Exception err)
    {
    err.printStackTrace();
    }
    }
    }

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: java program to execute an external application

    Just because something is possible in C# does not mean it's possible in Java.

    And it's **possible** in Java. It's just going to involve some native code.

    You apparently have your own ideas though, so the best I can do is wish you luck. Good luck!
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java program to execute an external application

    Thank you KevinWorkman. I am looking at some posts. These might help me.

    Execute an external program - Real's Java How-to

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: java program to execute an external application

    @harleen58: Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly using code or highlight tags per the above link.

Similar Threads

  1. Execute Linux commands through java program.
    By ars42025 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 25th, 2013, 03:39 AM
  2. How to execute an executable JAR from within Java program?
    By Hawke in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: July 8th, 2013, 02:41 PM
  3. Embedding Java application into external client
    By 1372586 in forum Java Networking
    Replies: 3
    Last Post: November 3rd, 2011, 08:57 AM
  4. Interaction with external application
    By righi in forum What's Wrong With My Code?
    Replies: 8
    Last Post: October 2nd, 2010, 08:37 AM
  5. How to execute a Java program independent of Netbeans.
    By ShaunB in forum Java Theory & Questions
    Replies: 4
    Last Post: January 19th, 2010, 05:23 AM

Tags for this Thread